def put(self, request, project_uuid):
     user = request.user
     group = get_user_group(user.username)
     project = get_group_project(group, project_uuid)
     if not project:
         return Response("Project with UUID=%s does not " "exist" % project_uuid, status=status.HTTP_400_BAD_REQUEST)
     data = request.data
     serializer = ProjectSerializer(project, data=data, context={"request": request})
     if serializer.is_valid():
         serializer.save()
         response = Response(serializer.data, status=status.HTTP_201_CREATED)
         return response
     else:
         return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例#2
0
 def delete(self, request, project_uuid):
     user = request.user
     group = get_user_group(user.username)
     project = get_group_project(group, project_uuid)
     if not project:
         return Response(
             "Project with UUID=%s does not "
             "exist" % project_uuid,
             status=status.HTTP_400_BAD_REQUEST
         )
     running_resources = project.has_running_resources()
     if running_resources:
         return Response(
             "Project %s has running resources. These resources "
             "MUST be transferred or deleted before deleting the project." %
             project.name,
             status=status.HTTP_409_CONFLICT
         )
     project.delete_project()
     serialized_data = ProjectSerializer(
         project, context={
             "request": request
         }
     ).data
     response = Response(serialized_data)
     return response
 def post(self, request):
     user = request.user
     data = request.data
     # Default to creating for the 'user-group'
     if not data.get("owner"):
         data["owner"] = user.username
     elif not Group.check_access(user, data["owner"]):
         return failure_response(
             status.HTTP_403_FORBIDDEN,
             "Current User: %s - Cannot assign project for group %s" % (user.username, data["owner"]),
         )
     serializer = ProjectSerializer(data=data, context={"request": request})
     if serializer.is_valid():
         serializer.save()
         response = Response(serializer.data, status=status.HTTP_201_CREATED)
         return response
     else:
         return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例#4
0
 def get(self, request):
     user = request.user
     group = get_user_group(user.username)
     projects = group.projects.filter(
         Q(end_date=None) | Q(end_date__gt=timezone.now()))
     serialized_data = ProjectSerializer(
         projects, many=True,
         context={"request": request}).data
     response = Response(serialized_data)
     return response
示例#5
0
 def put(self, request, project_uuid):
     user = request.user
     group = get_user_group(user.username)
     project = get_group_project(group, project_uuid)
     if not project:
         return Response("Project with UUID=%s does not "
                         "exist" % project_uuid,
                         status=status.HTTP_400_BAD_REQUEST)
     data = request.data
     serializer = ProjectSerializer(project,
                                    data=data,
                                    context={"request": request})
     if serializer.is_valid():
         serializer.save()
         response = Response(serializer.data,
                             status=status.HTTP_201_CREATED)
         return response
     else:
         return Response(serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
示例#6
0
 def post(self, request):
     user = request.user
     data = request.data
     # Default to creating for the 'user-group'
     if not data.get('owner'):
         data['owner'] = user.username
     elif not Group.check_access(user, data['owner']):
         return failure_response(
             status.HTTP_403_FORBIDDEN,
             "Current User: %s - Cannot assign project for group %s" %
             (user.username, data['owner']))
     serializer = ProjectSerializer(data=data, context={"request": request})
     if serializer.is_valid():
         serializer.save()
         response = Response(serializer.data,
                             status=status.HTTP_201_CREATED)
         return response
     else:
         return Response(serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
示例#7
0
 def get(self, request, project_uuid):
     """
     """
     user = request.user
     group = get_user_group(user.username)
     project = get_group_project(group, project_uuid)
     if not project:
         return Response("Project with UUID=%s "
                         "does not exist" % project_uuid,
                         status=status.HTTP_400_BAD_REQUEST)
     serialized_data = ProjectSerializer(project,
                                         context={"request": request}).data
     response = Response(serialized_data)
     return response