Пример #1
0
 def form_valid(self, form):
     cd = form.cleaned_data
     try:
         bucket = form.save(commit=False)
         bucket.created_by = self.request.user
         bucket.company = self.request.user.profile.company
         bucket.save()
         self.object = bucket
         messages.success(self.request, "KRA bucket for year '%s' created successfully" % cd['year'])
         NotificationManager.bucket_update_notification(self.request, bucket)
         return HttpResponseRedirect(self.get_success_url())
     except IntegrityError:
         form.add_error("year", "Sorry, your company already have a KRA bucket for year '%s'" % cd['year'])
         return self.render_to_response(self.get_context_data(form=form))
Пример #2
0
 def get(self, request, *args, **kwargs):
     bucket = get_object_or_404(KraBucket, reference=kwargs.get("reference"))
     if "assessment" in request.GET:
         bucket.allow_final_assessment = not bucket.allow_final_assessment
     elif "self-assessment" in request.GET:
         bucket.allow_self_assessment = not bucket.allow_self_assessment
     else:
         if bucket.status == constants.KRA_BUCKET_CLOSED_STATUS:
             bucket.status = constants.KRA_BUCKET_OPEN_STATUS
         else:
             bucket.status = constants.KRA_BUCKET_CLOSED_STATUS
     bucket.updated_by = request.user
     bucket.save()
     NotificationManager.bucket_update_notification(request, bucket)
     messages.success(request, "KRA Bucket updated successfully")
     return super(KRABucketToggle, self).get(request, *args, **kwargs)