mirror of https://github.com/openspug/spug
A api update
parent
1bb7b99db2
commit
138181edb1
|
@ -6,11 +6,11 @@ from apps.app.models import App
|
||||||
|
|
||||||
class DeployRequest(models.Model, ModelMixin):
|
class DeployRequest(models.Model, ModelMixin):
|
||||||
STATUS = (
|
STATUS = (
|
||||||
('-2', '发布失败'),
|
('-3', '发布异常'),
|
||||||
('-1', '已驳回'),
|
('-1', '已驳回'),
|
||||||
('1', '待审核'),
|
('1', '待审核'),
|
||||||
('2', '待发布'),
|
('2', '待发布'),
|
||||||
('3', '已完成'),
|
('3', '发布成功'),
|
||||||
)
|
)
|
||||||
app = models.ForeignKey(App, on_delete=models.CASCADE)
|
app = models.ForeignKey(App, on_delete=models.CASCADE)
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.views.generic import View
|
from django.views.generic import View
|
||||||
from django.db.models import F
|
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.models import DeployRequest
|
||||||
from apps.deploy.utils import deploy_dispatch
|
from apps.deploy.utils import deploy_dispatch
|
||||||
from apps.app.models import App
|
from apps.app.models import App
|
||||||
|
@ -83,3 +83,23 @@ class RequestDetailView(View):
|
||||||
outputs.update(local={'data': f'{human_time()} 建立接连... '})
|
outputs.update(local={'data': f'{human_time()} 建立接连... '})
|
||||||
targets = [{'id': x.id, 'title': f'{x.name}({x.hostname}:{x.port})'} for x in hosts]
|
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})
|
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)
|
||||||
|
|
Loading…
Reference in New Issue