Example #1
0
 def put(self, request, pk, *args, **kwargs):
     if is_elemen(request.user):
         partial = kwargs.pop('partial', False)
         instance = self.get_object(pk)
         if instance.status.status == 'pending':
             serializer = KenalanSerializer(instance,
                                            data=request.data,
                                            partial=partial)
             serializer.is_valid(raise_exception=True)
             serializer.save()
             return Response(GetKenalanSerializer(instance).data)
         else:
             raise PermissionDenied
     elif is_maba(request.user):
         partial = kwargs.pop('partial', False)
         instance = self.get_object(pk)
         if instance.status.status == 'rejected' or instance.status.status == 'saved':
             data = request.data
             status = KenalanStatus.objects.get(id=data['status'])
             if status.status != 'pending' and status.status != 'saved':
                 raise PermissionDenied
             serializer = KenalanSerializer(instance,
                                            data=request.data,
                                            partial=partial)
             serializer.is_valid(raise_exception=True)
             serializer.save()
             return Response(GetKenalanSerializer(instance).data)
         else:
             raise PermissionDenied
     else:
         raise PermissionDenied
Example #2
0
 def get_queryset(self):
     if is_maba(self.request.user):
         queryset = DetailKenalan.objects.all().filter(
             kenalan__user_maba=self.request.user)
     elif is_elemen(self.request.user):
         queryset = DetailKenalan.objects.all().filter(
             kenalan__user_elemen=self.request.user)
     else:
         queryset = DetailKenalan.objects.all()
     return queryset
Example #3
0
 def get_queryset(self):
     if is_maba(self.request.user):
         queryset = Kenalan.objects.all().filter(
             user_maba=self.request.user).order_by('-status', '-updated_at')
     elif is_elemen(self.request.user):
         queryset = Kenalan.objects.all().filter(
             user_elemen=self.request.user).exclude(
                 status=DRAFT_STATUS_ID).order_by('-status', '-updated_at')
     else:
         queryset = Kenalan.objects.all()
     return queryset