Пример #1
0
 def put(self, request, pk, format=None):
     chore = self.get_object(pk)
     serializer = ChoreSerializer(chore, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Пример #2
0
 def put(self, request, format=None):
     queryset = Chore.objects.all()
     seri = ChoreSerializer(queryset, many=True)
     serializer = ChoreSerializer(queryset, many=True, data=seri.data)
     if serializer.is_valid():
         serializer.save(assigned_to=None, assigned=False)
     return Response(serializer.data)
Пример #3
0
    def put(self, request, pk, format=None):
        chore = self.get_object(pk)
        if chore.assigned is True:
            return Response('"'+chore.name+'"'+' is already assigned', status=status.HTTP_412_PRECONDITION_FAILED)
        else:
            seri = ChoreSerializer(chore)
            serializer = ChoreSerializer(chore, data=seri.data)

            if serializer.is_valid():
                serializer.save(assigned_to=self.request.user, assigned=True)
                return Response(serializer.data)

            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Пример #4
0
    def put(self, request, pk, format=None):
        chore = self.get_object(pk)
        if chore.assigned is False:
            return Response('"'+chore.name+'"'+' is not assigned', status=status.HTTP_412_PRECONDITION_FAILED)
        elif chore.assigned is True and chore.expired is False:
            return Response('"'+chore.name+'"'+' has not yet expired', status=status.HTTP_412_PRECONDITION_FAILED)
        elif chore.assigned is True and chore.expired is True and chore.claimed is True:
            return Response('"'+chore.name+'"'+' is already claimed', status=status.HTTP_412_PRECONDITION_FAILED)
        else:
            seri = ChoreSerializer(chore)
            serializer = ChoreSerializer(chore, data=seri.data)

            if serializer.is_valid():
                serializer.save(claimed=True, claimed_by=self.request.user)
                return Response(serializer.data)

            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Пример #5
0
    def put(self, request, pk, format=None):
        chore = self.get_object(pk=pk)
        if chore.assigned is False:
            return Response('"'+chore.name+'"'+' is not assigned', status=status.HTTP_412_PRECONDITION_FAILED)
        if chore.expired is True:
            return Response('"'+chore.name+'"'+' is already expired', status=status.HTTP_412_PRECONDITION_FAILED)
        elif chore.assigned is True and self.Days[chore.due_day] >= self.today_as_weekday:
            return Response('The due day for '+'"'+chore.name+'"'+' has not passed', status=status.HTTP_412_PRECONDITION_FAILED)
        else:
            seri = ChoreSerializer(chore)
            serializer = ChoreSerializer(chore, data=seri.data)

            if serializer.is_valid():
                serializer.save(expired=True)
                return Response(serializer.data)

            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Пример #6
0
 def post(self, request, format=None):
     serializer = ChoreSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save(owner=self.request.user)
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)