Пример #1
0
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})
Пример #2
0
def template_create_post():
    name = request.form['name'].strip()
    if not name:
        return jsonify(msg='name is blank')

    if Template.read('tpl_name=%s', [name]):
        return jsonify(msg='name already existent')

    tpl_id = Template.insert({'tpl_name': name, 'create_user': g.user.name})
    if tpl_id:
        return jsonify(msg='', id=tpl_id)

    return jsonify(msg='create fail')
Пример #3
0
def template_create_post():
    name = request.form['name'].strip()
    if not name:
        return jsonify(msg='name is blank')

    if Template.read('tpl_name=%s', [name]):
        return jsonify(msg='name already existent')

    tpl_id = Template.insert({'tpl_name': name, 'create_user': g.user.name})
    if tpl_id:
        return jsonify(msg='', id=tpl_id)

    return jsonify(msg='create fail')
Пример #4
0
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='')
Пример #5
0
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
                           })
Пример #6
0
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())
Пример #7
0
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='')
Пример #8
0
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())
Пример #9
0
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='')
Пример #10
0
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,
                           })
Пример #11
0
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='')
Пример #12
0
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='')
Пример #13
0
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)
Пример #14
0
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
                           })
Пример #15
0
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='')
Пример #16
0
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,
        }
    )
Пример #17
0
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,
    })
Пример #18
0
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)
Пример #19
0
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,
                           })
Пример #20
0
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())
Пример #21
0
def api_template_query():
    q = request.args.get('query', '').strip()
    limit = int(request.args.get('limit', '10'))
    ts, _ = Template.query(1, limit, q)
    ts = [t.to_json() for t in ts]
    return jsonify(data=ts)
Пример #22
0
def api_template_query():
    q = request.args.get('query', '').strip()
    limit = int(request.args.get('limit', '10'))
    ts, _ = Template.query(1, limit, q)
    ts = [t.to_json() for t in ts]
    return jsonify(data=ts)