def template_view_get(tpl_id): tpl_id = int(tpl_id) t = Template.get(tpl_id) if not t: return jsonify(msg='no such template') t.parent = Template.get(t.parent_id) ss = Strategy.select_vs(where='tpl_id = %s', params=[tpl_id], order='metric') t.action = Action.get(t.action_id) return render_template('portal/template/view.html', data={'tpl': t, 'ss': ss})
def api_template_get(tpl_id): tpl_id = int(tpl_id) t = Template.get(tpl_id) if not t: return jsonify(msg='no such tpl') return jsonify(msg='', data=t.to_json())
def template_view_get(tpl_id): tpl_id = int(tpl_id) t = Template.get(tpl_id) if not t: return jsonify(msg='no such template') t.parent = Template.get(t.parent_id) ss = Strategy.select_vs(where='tpl_id = %s', params=[tpl_id], order='metric') t.action = Action.get(t.action_id) return render_template('portal/template/view.html', data={ 'tpl': t, 'ss': ss })
def template_update_get(tpl_id): tpl_id = int(tpl_id) t = Template.get(tpl_id) if not t: return jsonify(msg='no such template') t.parent = Template.get(t.parent_id) ss = Strategy.select_vs(where='tpl_id = %s', params=[tpl_id], order='metric') t.action = Action.get(t.action_id) log.debug(t) for s in ss: s.hook = Hook.total(where="strategy_id={id}".format(id=s.id)) return render_template('portal/template/update.html', data={ 'tpl': t, 'ss': ss })
def template_fork_get(tpl_id): tpl_id = int(tpl_id) t = Template.get(tpl_id) if not t: return jsonify(msg='no such template') new_id = t.fork(g.user.name) if new_id == -1: return jsonify(msg='name[copy_of_%s] has already existent' % t.tpl_name) return jsonify(msg='', id=new_id)
def template_binds_get(tpl_id): tpl_id = int(tpl_id) t = Template.get(tpl_id) if not t: return jsonify(msg='no such template') groups = GrpTpl.grp_list(tpl_id) return render_template('portal/template/groups.html', data={ "gs": groups, "tpl": t, })
def host_templates_get(host_id): host_id = int(host_id) h = Host.read('id = %s', params=[host_id]) if not h: return jsonify(msg='no such host') group_ids = GroupHost.group_ids(h.id) templates = GrpTpl.tpl_set(group_ids) for v in templates: v.parent = Template.get(v.parent_id) return render_template('portal/host/templates.html', **locals())
def template_rename_post(tpl_id): tpl_id = int(tpl_id) t = Template.get(tpl_id) if not t: return jsonify(msg='no such template') name = request.form['name'].strip() parent_id = request.form.get('parent_id', '') if not parent_id: parent_id = 0 Template.update_dict({'tpl_name': name, 'parent_id': parent_id}, 'id=%s', [tpl_id]) return jsonify(msg='')
def template_rename_post(tpl_id): tpl_id = int(tpl_id) t = Template.get(tpl_id) if not t: return jsonify(msg='no such template') name = request.form['name'].strip() parent_id = request.form.get('parent_id', '') if not parent_id: parent_id = 0 Template.update_dict({ 'tpl_name': name, 'parent_id': parent_id }, 'id=%s', [tpl_id]) return jsonify(msg='')
def template_action_update_post(tpl_id): tpl_id = int(tpl_id) t = Template.get(tpl_id) if not t: return jsonify(msg='no such template') uic = request.form['uic'].strip() url = request.form['url'].strip() callback = request.form['callback'].strip() before_callback_sms = request.form['before_callback_sms'].strip() before_callback_mail = request.form['before_callback_mail'].strip() after_callback_sms = request.form['after_callback_sms'].strip() after_callback_mail = request.form['after_callback_mail'].strip() if t.action_id > 0: # update Action.update_dict( { 'uic': uic, 'url': url, 'callback': callback, 'before_callback_sms': before_callback_sms, 'before_callback_mail': before_callback_mail, 'after_callback_sms': after_callback_sms, 'after_callback_mail': after_callback_mail }, 'id=%s', [t.action_id] ) else: # insert action_id = Action.insert({ 'uic': uic, 'url': url, 'callback': callback, 'before_callback_sms': before_callback_sms, 'before_callback_mail': before_callback_mail, 'after_callback_sms': after_callback_sms, 'after_callback_mail': after_callback_mail }) if action_id <= 0: return jsonify(msg='insert action fail') Template.update_dict({'action_id': action_id}, 'id=%s', [t.id]) return jsonify(msg='')
def templates_get(): page = int(request.args.get('p', 1)) limit = int(request.args.get('limit', 10)) query = request.args.get('q', '').strip() mine = request.args.get('mine', '1') me = g.user.name if mine == '1' else None vs, total = Template.query(page, limit, query, me) for v in vs: v.parent = Template.get(v.parent_id) return render_template('portal/template/list.html', data={ 'vs': vs, 'total': total, 'query': query, 'limit': limit, 'page': page, 'mine': mine, })
def template_delete_get(tpl_id): tpl_id = int(tpl_id) t = Template.get(tpl_id) if not t: return jsonify(msg='no such template') if not t.writable(g.user): return jsonify(msg='no permission') Template.delete_one(tpl_id) action_id = t.action_id if action_id: Action.delete_one(action_id) Strategy.delete('tpl_id = %s', [tpl_id]) GrpTpl.unbind_tpl(tpl_id) return jsonify(msg='')
def template_action_update_post(tpl_id): tpl_id = int(tpl_id) t = Template.get(tpl_id) if not t: return jsonify(msg='no such template') uic = request.form['uic'].strip() url = request.form['url'].strip() callback = request.form['callback'].strip() before_callback_sms = request.form['before_callback_sms'].strip() before_callback_mail = request.form['before_callback_mail'].strip() after_callback_sms = request.form['after_callback_sms'].strip() after_callback_mail = request.form['after_callback_mail'].strip() if t.action_id > 0: # update Action.update_dict( { 'uic': uic, 'url': url, 'callback': callback, 'before_callback_sms': before_callback_sms, 'before_callback_mail': before_callback_mail, 'after_callback_sms': after_callback_sms, 'after_callback_mail': after_callback_mail }, 'id=%s', [t.action_id]) else: # insert action_id = Action.insert({ 'uic': uic, 'url': url, 'callback': callback, 'before_callback_sms': before_callback_sms, 'before_callback_mail': before_callback_mail, 'after_callback_sms': after_callback_sms, 'after_callback_mail': after_callback_mail }) if action_id <= 0: return jsonify(msg='insert action fail') Template.update_dict({'action_id': action_id}, 'id=%s', [t.id]) return jsonify(msg='')
def templates_get(): page = int(request.args.get('p', 1)) limit = int(request.args.get('limit', 10)) query = request.args.get('q', '').strip() mine = request.args.get('mine', '1') me = g.user.name if mine == '1' else None vs, total = Template.query(page, limit, query, me) for v in vs: v.parent = Template.get(v.parent_id) return render_template( 'portal/template/list.html', data={ 'vs': vs, 'total': total, 'query': query, 'limit': limit, 'page': page, 'mine': mine, } )