コード例 #1
0
 def put(self, request):
     queryset = Quiz.objects.get(id=request.data['id'])
     serializer = QuizSerializer(queryset, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_200_OK)
     return Response(serializer.errors, status=status.HTTP_404_NOT_FOUND)
コード例 #2
0
ファイル: views.py プロジェクト: regevfarag/funtestic_backend
    def put(self, request):
        try:
            child_id = CbcEngine.get_engine().encrypt(request.data['child_id'])
            child = Child.objects.get(id_number=child_id)
            parent = child.parent
            if parent.user.username != request.user.username:
                raise exceptions.AuthenticationFailed(
                    detail='Not authorized request.')
        except KeyError:
            return Response('One of the fields are missing.',
                            status=status.HTTP_400_BAD_REQUEST)
        except Child.DoesNotExist:
            return Response('child does not exist.',
                            status=status.HTTP_400_BAD_REQUEST)

        request.data['child_id'] = child_id
        serializer = QuizSerializer(data=request.data)
        if not serializer.is_valid():
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
        try:
            serializer.save()
        except IntegrityError:
            return Response('Quiz is already exists',
                            status=status.HTTP_400_BAD_REQUEST)
        return Response('Quiz added successfully!')
コード例 #3
0
 def put(self, request, pk, format=None):
     quiz = self.get_object(pk)
     serializer = QuizSerializer(quiz,
                                 data=request.data,
                                 context={'request': request})
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_200_OK)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
コード例 #4
0
 def post(self, request):
     serializer = QuizSerializer(data=request.data)
     try:
         if serializer.is_valid():
             serializer.save()
             return Response(serializer.data,
                             status=status.HTTP_201_CREATED)
     except Exception as e:
         return Response(serializer.errors,
                         status=status.HTTP_404_NOT_FOUND)
コード例 #5
0
ファイル: views.py プロジェクト: kasimbozdag/SWE_573
 def post(self, request, *args, **kwargs):
     user = request.user
     data = request.data
     lesson = get_object_or_404(Lesson, pk=kwargs.get("pk"))
     quiz = {
         "owner": user.pk,
         "lesson": kwargs.get("pk"),
     }
     serializer = QuizSerializer(data=quiz)
     serializer.is_valid(raise_exception=True)
     serializer.save()
     return Response(serializer.data, status=HTTP_200_OK)