示例#1
0
 def put(self, request, project_id):
     """
     """
     user = request.user
     data = request.DATA
     group = get_user_group(user.username)
     project = group.projects.filter(id=project_id)
     if not project:
         return Response("Project with ID=%s does not exist" % project_id,
                         status=status.HTTP_400_BAD_REQUEST)
     project = project[0]
     serializer = ProjectSerializer(project,
                                    data=data,
                                    context={"user": request.user})
     if serializer.is_valid():
         #If the default project was renamed
         if project.name == "Default" \
                 and serializer.object.name != "Default":
             #Create another one.
             group.projects.get_or_create(name="Default")
         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 put(self, request, pk):
     project = self.get_object(pk)
     serializer = ProjectSerializer(instance=project, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors)
示例#3
0
 def post(self, request):
     """
     """
     user = request.user
     data = request.DATA
     if data.get('name') == 'Default':
         return Response("The 'Default' project name is reserved",
                         status=status.HTTP_409_CONFLICT)
     #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={"user": request.user})
     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 put(self, request, project_id):
     """
     """
     user = request.user
     data = request.DATA
     group = get_user_group(user.username)
     project = group.projects.filter(id=project_id)
     if not project:
         return Response("Project with ID=%s does not exist" % project_id,
                         status=status.HTTP_400_BAD_REQUEST)
     project = project[0]
     serializer = ProjectSerializer(project, data=data,
                                         context={"user":request.user})
     if serializer.is_valid():
         #If the default project was renamed
         if project.name == "Default" \
                 and serializer.object.name != "Default":
             #Create another one.
             group.projects.get_or_create(name="Default")
         serializer.save()
         response = Response(
                 serializer.data,
                 status=status.HTTP_201_CREATED)
         return response
     else:
         return Response(serializer.errors,
                 status=status.HTTP_400_BAD_REQUEST)
示例#5
0
 def post(self, request):
     """
     """
     user = request.user
     data = request.DATA
     if data.get('name') == 'Default':
         return Response("The 'Default' project name is reserved",
                         status=status.HTTP_409_CONFLICT)
     #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={"user":request.user})
     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 createProject(request):
    # product = Product.objects.get(id=pk)

    serializer = ProjectSerializer(data=request.data)
    if serializer.is_valid():
        serializer.save()
    return Response(serializer.data)
示例#7
0
def updateProject(request,pk):
    project = Project_model.objects.get(id=pk)
    serializer = ProjectSerializer(instance=project,data=request.data)
    
    if serializer.is_valid():
        serializer.save()

    return Response(serializer.data)
示例#8
0
 def put(self, request, pk, format=None):
     try:
         project = get_object(Project, pk)
         serializer = ProjectSerializer(project, data=request.data, partial=True)
         if serializer.is_valid(raise_exception=True):
             serializer.save()
             return Response(serializer.data)
     except ResourceNotFoundException as exc:
         return Response(data=exc.data, status=exc.status_code)
示例#9
0
 def create_project(self, data):
     from api.serializers import ProjectSerializer, ProfileItemSerializer
     data['creator'] = ProfileItemSerializer(self).data
     serializer = ProjectSerializer(data=data)
     if serializer.is_valid():
         serializer.save()
         project = serializer.instance
         if not project.is_self:
             from api.bot import BotNotification
             BotNotification.create_project(project)
         return project
     print(serializer.errors)
     return {'error': 'Ошибка сохранения проекта'}
示例#10
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)
示例#11
0
 def update_project(self, pk, data):
     from api.serializers import ProjectSerializer
     project = Project.objects.filter(pk=pk).first()
     if not project:
         return {'error': 'Проект не найден'}
     serializer = ProjectSerializer(instance=project,
                                    data=data,
                                    partial=True)
     if serializer.is_valid(raise_exception=False):
         serializer.save()
         project = serializer.instance
         if not project.is_self:
             from api.bot import BotNotification
             if project.creator == self:
                 BotNotification.update_project(project)
             if project.user == self:
                 BotNotification.accept_project(project)
         return serializer.instance
     print(serializer.errors)
     return {'error': 'Ошибка сохранения проекта'}
示例#12
0
 def put(self, request, project_id):
     """
     """
     user = request.user
     data = request.DATA
     group = get_user_group(user.username)
     project = group.projects.filter(id=project_id)
     if not project:
         return Response("Project with ID=%s does not exist" % project_id,
                         status=status.HTTP_400_BAD_REQUEST)
     project = project[0]
     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)
示例#13
0
 def put(self, request, project_id):
     """
     """
     user = request.user
     data = request.DATA
     group = get_user_group(user.username)
     project = group.projects.filter(id=project_id)
     if not project:
         return Response("Project with ID=%s does not exist" % project_id,
                         status=status.HTTP_400_BAD_REQUEST)
     project = project[0]
     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)
示例#14
0
 def patch(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,
                                    partial=True,
                                    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)
示例#15
0
 def post(self, request, format=None):
     serializer = ProjectSerializer(data=request.data)
     if serializer.is_valid(raise_exception=True):
         serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
示例#16
0
 def post(self, request):
     serializer = ProjectSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors)