Exemple #1
0
 def post(self, request, id):
     project_form = ProjectForm(request.POST)
     if project_form.is_valid():
         project = Project.objects.get(id=id)
         project.name = request.POST['name']
         project.type = request.POST['type']
         project.detail = request.POST['detail']
         project.creator = UserProfile.objects.get(username=request.user)
         project.save()
     return HttpResponseRedirect(reverse('project_list'))
Exemple #2
0
    async def post(self, *args, **kwargs):
        """
        新增项目数据
        """

        param = self.request.body.decode('utf-8')
        param = json.loads(param)
        form = ProjectForm.from_json(param)
        name = form.name.data

        if form.validate():
            try:
                await self.application.objects.get(Project, name=name)
                return self.json(JsonResponse(code=10007))

            except Project.DoesNotExist:
                project = await self.application.objects.create(
                    Project,
                    name=name,
                    desc=form.desc.data,
                    env=form.env.data,
                    creator=self.current_user)
                return self.json(
                    JsonResponse(code=1, data={"projectId": project.id}))

        else:
            self.set_status(400)
            return self.json(JsonResponse(code=10004, msg=form.errors))
Exemple #3
0
    async def patch(self, project_id, *args, **kwargs):
        """
        更新项目数据
        :param project_id: 更新的项目id
        """

        param = self.request.body.decode('utf-8')
        param = json.loads(param)
        form = ProjectForm.from_json(param)

        if form.validate():

            try:
                existed_project = await self.application.objects.get(
                    Project, id=int(project_id))
                existed_project.name = form.name.data
                existed_project.env = form.env.data
                existed_project.desc = form.desc.data
                await self.application.objects.update(existed_project)
                return self.json(JsonResponse(code=1, data={"id": project_id}))

            except Project.DoesNotExist:
                self.set_status(404)
                return self.json(JsonResponse(code=10009))

        else:
            self.set_status(400)
            return self.json(JsonResponse(code=10004, msg=form.errors))
    async def patch(self, project_id, *args, **kwargs):

        param = self.request.body.decode('utf-8')
        param = json.loads(param)
        form = ProjectForm.from_json(param)

        if form.validate():
            name = form.name.data
            desc = form.desc.data
            try:
                existed_project = await self.application.objects.get(
                    Project, id=int(project_id))
                existed_project.name = name
                existed_project.desc = desc
                await self.application.objects.update(existed_project)
                return self.json(
                    Result(code=1, msg="项目更新成功!", data={"id": project_id}))

            except Project.DoesNotExist:
                self.set_status(404)
                return self.json(Result(code=10020, msg="项目不存在!"))

        else:
            self.set_status(400)
            return self.json(Result(code=10090, msg=form.errors))
    async def post(self, *args, **kwargs):

        param = self.request.body.decode('utf-8')
        param = json.loads(param)
        form = ProjectForm.from_json(param)
        name = form.name.data
        desc = form.desc.data

        if name is None:
            return self.json(Result(code=10080, msg="参数有误, 参数name不可缺少"))
        if desc is None:
            return self.json(Result(code=10080, msg="参数有误, 参数desc不可缺少"))

        if form.validate():
            try:
                existed_project = await self.application.objects.get(Project,
                                                                     name=name)
                return self.json(Result(code=10020, msg='这个项目已经被创建!'))

            except Project.DoesNotExist:
                project = await self.application.objects.create(
                    Project, name=name, desc=desc, creator=self.current_user)
                return self.json(
                    Result(code=1,
                           msg="创建项目成功!",
                           data={"projectId": project.id}))

        else:
            self.set_status(400)
            return self.json(Result(code=10090, msg=form.errors))
Exemple #6
0
    def get(self, request):

        user = UserProfile.objects.get(username=request.user)

        project_form = ProjectForm({'creator': user.username})

        return render(request, 'project_add.html', {'obj_form': project_form})
Exemple #7
0
    def post(self, request):
        project_form = ProjectForm(request.POST)

        if project_form.is_valid():
            name = request.POST['name']
            type = request.POST['type']
            detail = request.POST['detail']
            creator = UserProfile.objects.get(username=request.user)
            project = Project(name=name,
                              type=type,
                              detail=detail,
                              creator=creator)
            project.save()
        else:
            return render(request, 'project_add.html',
                          {'error': project_form.errors})
        return HttpResponseRedirect(reverse('project_list'))
Exemple #8
0
def project_view(request, project_id):
    """
    - return project corresponding to project_id
    - handle project modification form submition
    - raise 404 if project is not found or project doesn't belong to
    the current user
    """
    if request.user.is_superuser:
        project = get_object_or_404(Project, pk=project_id)
    else:
        project = get_object_or_404(Project, owner=request.user, pk=project_id)
    if request.method == "POST":
        form = ProjectForm(request.POST, instance=project)
        if form.is_valid():
            form.save()
    else:
        form = ProjectForm(instance=project)

    context = {
        'project':
        project,
        'new_application_form':
        NewApplicationForm({'project_id': project.id},
                           prefix='new_application'),
        'project_form':
        form
    }
    return render_response(request, 'project/project_view.html', context)
 def get(self, request, *args, **kwargs):
     return JsonResponse(
         {
             'task_queue_choice_form': TaskQueueChoiceForm().as_p(),
             'task_queue_create_form': TaskQueueForm().as_p(),
             'project_choice_form': ProjectChoiceForm().as_p(),
             'project_create_form': ProjectForm().as_p()
         },
         encoder=DjangoJSONEncoder,
         safe=False)
Exemple #10
0
    def get(self, request, id):
        project = Project.objects.get(id=id)

        user = UserProfile.objects.get(username=project.creator)

        project_form = ProjectForm({
            'name': project.name,
            'type': project.type,
            'creator': user.username,
            'detail': project.detail
        })
        return render(request, 'project_edit.html', {'obj_form': project_form})
Exemple #11
0
def project_view(request, project_id):
    """
    - return project corresponding to project_id
    - handle project modification form submition
    - raise 404 if project is not found or project doesn't belong to
    the current user
    """
    if request.user.is_superuser:
        project = get_object_or_404(Project, pk=project_id)
    else:
        project = get_object_or_404(Project, owner=request.user, pk=project_id)
    if request.method == "POST":
        form = ProjectForm(request.POST, instance=project)
        if form.is_valid():
            form.save()
    else:
        form = ProjectForm(instance=project)

    context = {'project': project,
               'new_application_form': NewApplicationForm(
                   {'project_id': project.id}, prefix='new_application'),
               'project_form': form}
    return render_response(request, 'project/project_view.html', context)
Exemple #12
0
 def get(self, request):
     project_from = ProjectForm()
     return render(request, 'project.html', {"obj_form": project_from})