def patch(self, request, pk): form = self.get_object(pk) serializer = FormSerializer(form, data=request.data, partial=True) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request): serializer = FormSerializer(data=request.data) if serializer.is_valid(): form = serializer.save() user = User.objects.filter(username=request.user).first() user.forms.add(form) return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def new_form(request): if request.method == 'POST': form = None form_serializer = FormSerializer(data=request.data) if form_serializer.is_valid(): form = form_serializer.save() user = User.objects.filter(username=request.user).first() user.forms.add(form) fields = request.data.get('fields', []) for field in fields: serializer = FormFieldSerializer(data=field) if serializer.is_valid(): form_field = serializer.save() form.fields.add(form_field) return Response(form_serializer.data, status=status.HTTP_200_OK) return Response({"forms": FormAnswer.objects.all()}, status=status.HTTP_200_OK)
def get(self, request, link): form = self.get_object(link) serializer = FormSerializer(form) return Response(serializer.data)
def get(self, request): forms = Form.objects.filter(user=request.user) serializer = FormSerializer(forms, many=True) return Response(serializer.data)
def get_forms(self, datalab): forms = Form.objects(datalab=datalab.id) serializer = FormSerializer(forms, many=True) return serializer.data