Beispiel #1
0
def project_list(request):
    if request.method == 'GET':
        projects = Project.objects.all()
        serializer = projectSerializer(projects, many=True)
        return JSONResponse(serializer.data)
    
    elif request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = projectSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data, status=201)
        return JSONResponse(serializer.data, status=400)
Beispiel #2
0
 def userProjects(self, request, userName, projectID=None):
     serializer_context = {
         'request': request,
     }
     if userName is not None:
         if projectID is None:   
             userID = project_api.get_user_id(userName)
             queryset = project_api.get_projects_for_user(userID)
         else:
             queryset = Project.objects.filter(id = projectID)
     #queryset = project_api.get_all_projects()
     serializer = projectSerializer(queryset,context=serializer_context, many=True)
     return Response(serializer.data)