def get(self, request, *args, **kwargs): user = request.user descendants = user.profile.directing_department.members.all().exclude( id=user.profile.id) if hasattr( user.profile, "directing_department") else user.profile.child_members.all() data = { "descendants": ProfileSerializer(descendants, many=True).data, "profile": ProfileSerializer(user.profile).data, "ancestor": ProfileSerializer(user.profile.manager).data, "tasks": TaskSerializer(user.profile.tasks, many=True).data, "pips": PipSerializer(user.pips.all(), many=True).data if hasattr( user, "pips") else [], "raised_pips": PipSerializer(user.raised_pips.all(), many=True).data if hasattr( user, "raised_pips") else [], "pending_tasks": TaskSerializer(user.profile.pending_tasks, many=True).data, "kras": KraSerializer(user.kras.all(), many=True).data if hasattr( user, "kras") else [] } return Response(utils.build_response(True, None, data))
def get(self, request, *args, **kwargs): if "reference" in kwargs: user = request.user buckets = user.profile.company.kra_buckets.all() instance = buckets.get(reference=kwargs['reference']) serializer = KraBucketSerializer(instance) data = serializer.data if hasattr(instance, "company_kra"): data["company_kra"] = CompanyKraSerializer( instance.company_kra).data else: data["company_kra"] = None try: manager_kra = Kra.objects.get(user=user.profile.manager.user, bucket=instance, status__in=[ constants.KRA_LOCKED_STATUS, constants.KRA_OPEN_STATUS, constants.KRA_CLOSED_STATUS ], is_draft=False) data["manager_kra"] = KraSerializer(manager_kra).data except: data["manager_kra"] = None if hasattr(instance, "kras"): data["team_kras"] = KraSerializer( instance.kras.filter(user__profile__in=self.request.user. profile.child_members.all(), is_draft=False), many=True).data else: kwargs["team_kras"] = [] return Response(utils.build_response(True, None, data)) else: try: serializer = KraBucketSerializer( request.user.profile.company.kra_buckets.all(), many=True) return Response( utils.build_response(True, None, serializer.data)) except: return Response(utils.build_response(True, None, []))
def get(self, request, *args, **kwargs): try: data = {} profile = request.user.profile.directing_department.members.get( id=kwargs['id']) kras = profile.user.kras.filter(is_draft=False) data["profile"] = ProfileSerializer(profile).data data["kras"] = KraSerializer(kras, many=True).data return Response(utils.build_response(True, None, data)) except: return Response(utils.build_response(False, "Invalid user", None))
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 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(): validated_data = serializer.validated_data kra = self.perform_update(serializer) message = "KRA setting saved as draft" if not validated_data.get("is_draft", False): message = "KRA setting submitted for assessment" if self.request.user.profile.manager: NotificationManager.kra_setting_notification( self.request, kra) return Response( utils.build_response(True, message, KraSerializer(kra).data)) return Response(utils.build_response(False, None, serializer.errors))