コード例 #1
0
 def put(self, request, pk, format=None):
     shared_profile = self.get_object(pk)
     serializer = SharedProfileSerializer(shared_profile, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response({'error': serializer.errors}, status=status.HTTP_400_BAD_REQUEST)
コード例 #2
0
class SharedProfileDetail(APIView):
    """
    Retrieve, update or delete a casting request of client.
    """
    def get_object(self, pk):
        try:
            return SharedProfile.objects.get(pk=pk)
        except SharedProfile.DoesNotExist:
            raise Http404

    @swagger_auto_schema(responses={200: SharedProfileDetailSerializer(many=False)})
    def get(self, request, pk, format=None):
        shared_profile = self.get_object(pk)
        serializer = SharedProfileDetailSerializer(shared_profile)
        return Response(serializer.data)

    @swagger_auto_schema(
        request_body=SharedProfileCreateSerializer(many=True),
        responses={200: SharedProfileSerializer(many=False)}
    )
    def put(self, request, pk, format=None):
        shared_profile = self.get_object(pk)
        serializer = SharedProfileSerializer(shared_profile, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response({'error': serializer.errors}, status=status.HTTP_400_BAD_REQUEST)

    @swagger_auto_schema(responses={200: 'OK'})
    def delete(self, request, pk, format=None):
        shared_profile = self.get_object(pk)
        shared_profile.delete()
        return Response({'id': int(pk)}, status=status.HTTP_200_OK)
コード例 #3
0
 def get(self, request, format=None):
     user = User.objects.get(pk=request.user.pk)
     client = Client.objects.get(user=user)
     team = Team.objects.get(client_id=client.id)
     team_member_ids = TeamMember.objects.filter(team_id=team.id)\
         .values_list('id', flat=True)\
         .order_by('id')
     shared_profiles = SharedProfile.objects.filter(team_member_id__in=team_member_ids)
     serializer = SharedProfileSerializer(shared_profiles, many=True)
     return Response(serializer.data)
コード例 #4
0
class SharedProfileList(APIView):
    """
    Retrieve all casting requests of client.
    """
    @swagger_auto_schema(responses={200: SharedProfileSerializer(many=True)})
    def get(self, request, format=None):
        user = User.objects.get(pk=request.user.pk)
        client = Client.objects.get(user=user)
        team = Team.objects.get(client_id=client.id)
        team_member_ids = TeamMember.objects.filter(team_id=team.id)\
            .values_list('id', flat=True)\
            .order_by('id')
        shared_profiles = SharedProfile.objects.filter(team_member_id__in=team_member_ids)
        serializer = SharedProfileSerializer(shared_profiles, many=True)
        return Response(serializer.data)