A api update

This commit is contained in:
雷二猛 2019-12-24 23:47:48 +08:00
parent 95ad5a149b
commit 61b697cd16
3 changed files with 20 additions and 5 deletions

View File

@ -73,11 +73,13 @@ class AppExtend1(models.Model, ModelMixin):
class AppExtend2(models.Model, ModelMixin): class AppExtend2(models.Model, ModelMixin):
app = models.OneToOneField(App, primary_key=True, on_delete=models.CASCADE) app = models.OneToOneField(App, primary_key=True, on_delete=models.CASCADE)
actions = models.TextField() server_actions = models.TextField()
host_actions = models.TextField()
def to_dict(self, *args, **kwargs): def to_dict(self, *args, **kwargs):
tmp = super().to_dict(*args, **kwargs) tmp = super().to_dict(*args, **kwargs)
tmp['actions'] = json.loads(self.actions) tmp['server_actions'] = json.loads(self.server_actions)
tmp['host_actions'] = json.loads(self.host_actions)
return tmp return tmp
def __repr__(self): def __repr__(self):

View File

@ -47,11 +47,15 @@ class AppView(View):
AppExtend1.objects.create(app=app, **extend_form) AppExtend1.objects.create(app=app, **extend_form)
elif form.extend == '2': elif form.extend == '2':
extend_form, error = JsonParser( extend_form, error = JsonParser(
Argument('actions', type=list, filter=lambda x: len(x), help='请输入执行动作') Argument('server_actions', type=list, help='请输入执行动作'),
Argument('host_actions', type=list, help='请输入执行动作')
).parse(request.body) ).parse(request.body)
if error: if error:
return json_response(error=error) return json_response(error=error)
extend_form.actions = json.dumps(extend_form.actions) if len(extend_form.server_actions) + len(extend_form.host_actions) == 0:
return json_response(error='请至少设置一个执行的动作')
extend_form.server_actions = json.dumps(extend_form.server_actions)
extend_form.host_actions = json.dumps(extend_form.host_actions)
if form.id: if form.id:
App.objects.filter(pk=form.id).update(**form) App.objects.filter(pk=form.id).update(**form)
AppExtend2.objects.filter(app_id=form.id).update(**extend_form) AppExtend2.objects.filter(app_id=form.id).update(**extend_form)

View File

@ -105,13 +105,22 @@ class RequestDetailView(View):
return json_response(error='为找到指定发布申请') return json_response(error='为找到指定发布申请')
hosts = Host.objects.filter(id__in=json.loads(req.host_ids)) hosts = Host.objects.filter(id__in=json.loads(req.host_ids))
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]
server_steps, host_steps = [], []
if req.app.extend == '2':
for item in json.loads(req.app.extend_obj.actions):
if item['target'] == 'server':
server_steps.append(item['name'])
else:
host_steps.append(item['name'])
return json_response({ return json_response({
'app_name': req.app.name, 'app_name': req.app.name,
'env_name': req.app.env.name, 'env_name': req.app.env.name,
'status': req.status, 'status': req.status,
'type': req.type, 'type': req.type,
'status_alias': req.get_status_display(), 'status_alias': req.get_status_display(),
'targets': targets 'targets': targets,
'server_steps': server_steps,
'host_steps': host_steps
}) })
def post(self, request, r_id): def post(self, request, r_id):