Example #1
0
File: views.py Project: duydb2/ZTC
    def post(self, request, service, pk=None, format=None):
        profile = self.get_object(pk, create=True)
        data = request.DATA
        serializer = ProfileSerializer(profile, data=data)
        if not serializer.is_valid():
            raise ParseError(detail=serializer.errors)

        serializer.save()
        return Response(serializer.data, status=status.HTTP_201_CREATED)
Example #2
0
File: views.py Project: duydb2/ZTC
    def post(self, request, service):
        data = request.DATA
        profiles = Profile.objects.all()
        profiles.delete()
        serializer = ProfileSerializer(data=data, many=True)
        if not serializer.is_valid():
            raise ParseError(detail=serializer.errors)

        serializer.save()

        return Response(serializer.data, status=status.HTTP_201_CREATED)
Example #3
0
File: views.py Project: duydb2/ZTC
    def post(self, request, service, pk=None, format=None):
	profile = self.get_object(pk, create=True)
 	data = request.DATA
       	serializer = ProfileSerializer(profile, data=data)
       	if not serializer.is_valid():
       	     raise ParseError(detail=serializer.errors)

       	serializer.save()
       	return Response(
       	    serializer.data,
       	    status=status.HTTP_201_CREATED
       	)
Example #4
0
File: views.py Project: duydb2/ZTC
    def post(self, request, service):
       	data = request.DATA 
        profiles = Profile.objects.all()
	profiles.delete()
      	serializer = ProfileSerializer(data=data, many=True)
       	if not serializer.is_valid():
       	     raise ParseError(detail=serializer.errors)

	serializer.save()

       	return Response(
       	    serializer.data,
       	    status=status.HTTP_201_CREATED
       	)
Example #5
0
File: views.py Project: duydb2/ZTC
def profile_list(request):
    if request.method == 'GET':
        profiles = Profile.objects.all()
        serializer = ProfileSerializer(profiles, many=True)
        return JSONResponse(serializer.data)

    elif request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = ProfileSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data, status=201)
        return JSONResponse(serializer.errors, status=400)

    else:
        return HttpResponse(status=405)
Example #6
0
File: views.py Project: duydb2/ZTC
def profile_detail(request, pk):
    try:
        profile = Profile.objects.get(pk=pk)
    except Profile.DoesNotExist:
        return HttpResponse(status=404)

    if request.method == 'GET':
        serializer = ProfileSerializer(profile)
        return JSONResponse(serializer.data)

    elif request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = ProfileSerializer(profile, data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data)
        return JSONResponse(serializer.errors, status=400)

    elif request.method == 'DELETE':
        profile.delete()
        return HttpResponse(status=204)

    else:
        return HttpResponse(status=405)