def form_valid(self, form): form.save() self.object.self_assessed = True self.object.save() NotificationManager.kra_update_notification(self.request, self.object) messages.success(self.request, "KRA Self-assessment completed successfully") return HttpResponseRedirect(self.object.get_absolute_url())
def post(self, request, *args, **kwargs): kra = get_object_or_404(Kra, identifier=kwargs["identifier"]) if kra.user != request.user and kra.user.profile.manager != request.user.profile: return Response( utils.build_response(False, "Permission denied", None)) serializer = KraCreateMessageSerializer(data=request.data) if serializer.is_valid(): serializer.save( user=request.user, kra=kra, file_type=serializer.validated_data["file"].content_type if "file" in serializer.validated_data and serializer.validated_data["file"] else None, filename=serializer.validated_data["file"].name if "file" in serializer.validated_data and serializer.validated_data["file"] else None) if not kra.is_draft: NotificationManager.kra_update_notification(request, kra) return Response( utils.build_response( True, "Message sent", KraMessagesSerializer(kra.messages.all(), many=True, context={ "request": request }).data)) return Response(utils.build_response(False, None, serializer.errors))
def post(self, request, *args, **kwargs): form = self.get_form() ratingForm = self.get_rating_form() if form.is_valid() and ratingForm.is_valid(): form.save() self.object = ratingForm.save() self.object.status = constants.KRA_CLOSED_STATUS self.object.save() messages.success(self.request, "KRA Assessment completed successfully") NotificationManager.kra_update_notification(request, self.object) return redirect(self.get_success_url()) else: return self.render_to_response(self.get_context_data(form=form, ratingForm=ratingForm))
def update(self, request, *args, **kwargs): partial = kwargs.pop('partial', False) instance = self.get_object() serializer = self.get_serializer(instance, data=request.data, partial=partial) if serializer.is_valid(): kra = self.perform_update(serializer) NotificationManager.kra_update_notification(self.request, kra) return Response( utils.build_response(True, None, KraSerializer(kra).data)) return Response(utils.build_response(False, None, serializer.errors))
def post(self, request, *args, **kwargs): self.object = self.get_object() self.new_messages.update(read=True) kra = self.object resp = {"error": True, "message": "Unexpected data"} if "message" in request.GET: form = MessageForm(request.POST, files=request.FILES) if form.is_valid(): message = form.save(commit=False) message.kra = kra message.user = request.user if form.cleaned_data.get("file"): message.file_type = form.cleaned_data.get("file").content_type message.filename = form.cleaned_data.get("file").name message.save() msgs = kra.messages.filter(pk__gte=message.pk) resp = {"success": True, "messages": render_to_string("kra/messages.html", {"messages": msgs, "user": request.user})} elif "modify" in request.GET: kra.status = constants.KRA_OPEN_STATUS kra.save() resp = {"success": True, "message": "KRA setting has been opened for modifications successfully"} elif "reject" in request.GET: kra.status = constants.KRA_REJECTED_STATUS kra.save() resp = {"success": True, "message": "KRA setting has been rejected successfully"} elif "accept" in request.GET: kra.is_accepted = True kra.save() resp = {"success": True, "message": "KRA setting has been accepted successfully"} else: if (self.object.hod_rating and not (self.is_hod or request.user.profile.is_ceo)) or (self.object.hod_rating and not request.user.profile.is_ceo): raise Http404() ratingForm = HODRatingForm(self.request.POST or None, instance=self.object, company=self.request.user.profile.company) if ratingForm.is_valid(): ratingForm.save() messages.success(request, "Rating updated successfully") return HttpResponseRedirect(request.META["HTTP_REFERER"]) return self.render_to_response(self.get_context_data(ratingForm=ratingForm)) if not kra.is_draft: NotificationManager.kra_update_notification(request, kra) return JsonResponse(resp)