From 138181edb1c018092b13fcfd6134f87c0b3bdecf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E4=BA=8C=E7=8C=9B?= Date: Sun, 22 Dec 2019 11:30:53 +0800 Subject: [PATCH] A api update --- spug_api/apps/deploy/models.py | 4 ++-- spug_api/apps/deploy/views.py | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/spug_api/apps/deploy/models.py b/spug_api/apps/deploy/models.py index cc79735..104ae65 100644 --- a/spug_api/apps/deploy/models.py +++ b/spug_api/apps/deploy/models.py @@ -6,11 +6,11 @@ from apps.app.models import App class DeployRequest(models.Model, ModelMixin): STATUS = ( - ('-2', '发布失败'), + ('-3', '发布异常'), ('-1', '已驳回'), ('1', '待审核'), ('2', '待发布'), - ('3', '已完成'), + ('3', '发布成功'), ) app = models.ForeignKey(App, on_delete=models.CASCADE) name = models.CharField(max_length=50) diff --git a/spug_api/apps/deploy/views.py b/spug_api/apps/deploy/views.py index 238b802..f012376 100644 --- a/spug_api/apps/deploy/views.py +++ b/spug_api/apps/deploy/views.py @@ -1,6 +1,6 @@ from django.views.generic import View from django.db.models import F -from libs import json_response, JsonParser, Argument, human_time +from libs import json_response, JsonParser, Argument, human_datetime, human_time from apps.deploy.models import DeployRequest from apps.deploy.utils import deploy_dispatch from apps.app.models import App @@ -83,3 +83,23 @@ class RequestDetailView(View): outputs.update(local={'data': f'{human_time()} 建立接连... '}) targets = [{'id': x.id, 'title': f'{x.name}({x.hostname}:{x.port})'} for x in hosts] return json_response({'token': token, 'outputs': outputs, 'targets': targets}) + + def patch(self, request, r_id): + form, error = JsonParser( + Argument('reason', required=False), + Argument('is_pass', type=bool, help='参数错误') + ).parse(request.body) + if error is None: + req = DeployRequest.objects.filter(pk=r_id).first() + if not req: + return json_response(error='未找到指定申请') + if not form.is_pass and not form.reason: + return json_response(error='请输入驳回原因') + if req.status != '1': + return json_response(error='该申请当前状态不允许审核') + req.approve_at = human_datetime() + req.approve_by = request.user + req.status = '2' if form.is_pass else '-1' + req.reason = form.reason + req.save() + return json_response(error=error)