def delete(self, request, pk, format=None): blocked_profile = self.get_object(pk) note = '{client} REMOVED BLOCK.'.format( client=blocked_profile.client.user.email) UserNoteManager.block_logger(None, blocked_profile.client.user, blocked_profile.talent.user, note, blocked_profile) blocked_profile.delete() return Response({'id': int(pk)}, status=status.HTTP_200_OK)
def post(self, request, format=None): user = request.user client = Client.objects.get(user_id=user.id) serializer = BlockedProfileCreateSerializer(data=request.data, many=False) if serializer.is_valid(): new_blocked_profile = BlockedProfile(client_id=client.id, **serializer.validated_data) new_blocked_profile.save() note = '{client} BLOCKED FOR {duration}.'.format( client=client.user.email, duration=new_blocked_profile.description) UserNoteManager.block_logger(None, client.user, new_blocked_profile.talent.user, note, new_blocked_profile) new_serializer = BlockedProfileDetailSerializer( new_blocked_profile, many=False) return Response(new_serializer.data, status=status.HTTP_201_CREATED) return Response({'error': serializer.errors}, status=status.HTTP_400_BAD_REQUEST)