def hook_update_post(): hid = request.form['hid'].strip() sid = request.form['sid'].strip() when_status = request.form['when_status'].strip() when_step = request.form['when_step'].strip() hook_method = request.form['hook_method'].strip() hook_url = request.form['hook_url'].strip() params = request.form['params'].strip() if not when_step or not hook_url: return jsonify(msg='when_step or hook_url is blank') if hid: # update Hook.update_dict( { 'when_status': when_status, 'when_step': when_step, 'hook_method': hook_method, 'hook_url': hook_url, 'params': params }, 'id=%s', [hid]) return jsonify(msg='') # insert Hook.insert({ 'strategy_id': sid, 'expression_id': 0, 'when_status': when_status, 'when_step': when_step, 'hook_method': hook_method, 'hook_url': hook_url, 'params': params }) return jsonify(msg='')
def hook_delete_get(hid): hid = int(hid) hook = Hook.get(hid) if not hook: return jsonify(msg='no such hook') Hook.delete_one(hid) return jsonify(msg='')
def strategy_delete_get(sid): sid = int(sid) s = Strategy.get(sid) if not s: return jsonify(msg='no such strategy') Hook.delete(where="strategy_id={id}".format(id=sid)) Strategy.delete_one(sid) return jsonify(msg='')
def hook_get(hid): hid = int(hid) hook = Hook.get(hid) if not hook: return jsonify(msg='no such hook') return jsonify(msg='', data=hook.to_json())
def api_get_hook(): hooks = Hook.select_vs() if not hooks: return jsonify(msg='Could not find any hooks') data = [] for hook in hooks: data.append(hook.to_json()) return jsonify(msg='ok', data=data)
def strategy_list_hook(sid): sid = int(sid) s = Strategy.get(sid) if not s: return jsonify(msg='no such strategy') hooks = Hook.select_vs(where="strategy_id={id}".format(id=sid)) data = [] for hook in hooks: data.append(hook.to_json()) return jsonify(msg='', data=data)
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) for s in ss: s.hook = Hook.total(where="strategy_id={id}".format(id=s.id)) return render_template('portal/template/view.html', data={ 'tpl': t, 'ss': ss })