Esempio n. 1
0
	def post(self, request, format=json):
		print '----------------------------------------'
		data=JSONParser.parse(request)
		serializer=QuestionSerializer(data=data)
		if serializer.is_valid():
			serializer.save()
			return Response(serializer.data, status=200)
Esempio n. 2
0
 def post(self, request, format=json):
     print '----------------------------------------'
     data = JSONParser.parse(request)
     serializer = QuestionSerializer(data=data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=200)
Esempio n. 3
0
def post_question(request):
    if request.method == 'POST':
        print("data", request.data)
        serializer = QuestionSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Esempio n. 4
0
def post_question(request):
    if request.method == 'POST':
        print("data", request.data)
        serializer = QuestionSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Esempio n. 5
0
 def post(self, request):
     data = request.data
     serializer = QuestionSerializer(data=data)
     if serializer.is_valid():
         serializer.save()
         response = generateresponse('Success', 'question', serializer.data)
         return Response(response)
     else:
         raise InvalidInformation(serializer.errors)
Esempio n. 6
0
def addQuestion(request, format=json):
	#Post an order
	if request.method=='POST':
		data = JSONParser().parse(request)
		serializer = QuestionSerializer(data=data)
		if serializer.is_valid():
			serializer.save()
			return Response(serializer.data, status=200)
    	else:
        	return JSONRenderer().render(serializer.errors)
Esempio n. 7
0
def addQuestion(request, format=json):
    #Post an order
    if request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = QuestionSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=200)
    else:
        return JSONRenderer().render(serializer.errors)
Esempio n. 8
0
def create_question(request, format=None):
    resp_dict = dict(message='', error=0, result='')
    if request.method == 'POST':
        serializer = QuestionSerializer(data=request.data)
        if serializer.is_valid():
            if not request.user.is_anonymous:
                serializer.save(asked_by=request.user)
                serializer.save()
                resp_dict.update(result=serializer.data, message='Success')
                return Response(resp_dict, status=status.HTTP_201_CREATED)
            else:
                resp_dict.update(message='Not a valid user', error=1)
                return Response(resp_dict, status=status.HTTP_403_FORBIDDEN)
        else:
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)