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)
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!')
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)
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)
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)