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)
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)
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
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)
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