Пример #1
0
def opr_add_update(db, render):
    nodes = [(n.node_name, n.node_desc) for n in db.query(models.SlcNode)]
    form = opr_forms.opr_update_form(nodes)
    if not form.validates(source=request.forms):
        rules = db.query(models.SlcOperatorRule.rule_path).filter_by(
            operator_name=opr.operator_name)
        rules = [r[0] for r in rules]
        return render("sys_opr_form", form=form, rules=rules)
    opr = db.query(models.SlcOperator).get(form.d.id)

    if form.d.operator_pass:
        opr.operator_pass = md5(form.d.operator_pass).hexdigest()
    opr.operator_desc = form.d.operator_desc
    opr.operator_status = form.d.operator_status

    db.query(models.SlcOperatorNodes).filter_by(
        operator_name=opr.operator_name).delete()
    for node in request.params.getall("operator_nodes"):
        onode = models.SlcOperatorNodes()
        onode.operator_name = form.d.operator_name
        onode.node_name = node
        db.add(onode)

    db.query(models.SlcOperatorProducts).filter_by(
        operator_name=opr.operator_name).delete()
    for product_id in request.params.getall("operator_products"):
        oproduct = models.SlcOperatorProducts()
        oproduct.operator_name = form.d.operator_name
        oproduct.product_id = product_id
        db.add(oproduct)

    # update rules
    db.query(models.SlcOperatorRule).filter_by(
        operator_name=opr.operator_name).delete()

    for path in request.params.getall("rule_item"):
        item = permit.get_route(path)
        if not item: continue
        rule = models.SlcOperatorRule()
        rule.operator_name = opr.operator_name
        rule.rule_name = item['name']
        rule.rule_path = item['path']
        rule.rule_category = item['category']
        db.add(rule)

    permit.unbind_opr(opr.operator_name)
    for rule in db.query(
            models.SlcOperatorRule).filter_by(operator_name=opr.operator_name):
        permit.bind_opr(rule.operator_name, rule.rule_path)

    ops_log = models.SlcRadOperateLog()
    ops_log.operator_name = get_cookie("username")
    ops_log.operate_ip = get_cookie("login_ip")
    ops_log.operate_time = utils.get_currtime()
    ops_log.operate_desc = u'操作员(%s)修改操作员信息:%s' % (get_cookie("username"),
                                                   opr.operator_name)
    db.add(ops_log)

    db.commit()
    redirect("/opr")
Пример #2
0
def opr_add_update(db, render):
    nodes = [(n.node_name, n.node_desc) for n in db.query(models.SlcNode)]
    form = opr_forms.opr_update_form(nodes)
    if not form.validates(source=request.forms):
        rules = db.query(models.SlcOperatorRule.rule_path).filter_by(operator_name=opr.operator_name)
        rules = [r[0] for r in rules]
        return render("sys_opr_form", form=form, rules=rules)
    opr = db.query(models.SlcOperator).get(form.d.id)

    if form.d.operator_pass:
        opr.operator_pass = md5(form.d.operator_pass).hexdigest()
    opr.operator_desc = form.d.operator_desc
    opr.operator_status = form.d.operator_status

    db.query(models.SlcOperatorNodes).filter_by(operator_name=opr.operator_name).delete()
    for node in request.params.getall("operator_nodes"):
        onode = models.SlcOperatorNodes()
        onode.operator_name = form.d.operator_name
        onode.node_name = node
        db.add(onode)

    db.query(models.SlcOperatorProducts).filter_by(operator_name=opr.operator_name).delete()
    for product_id in request.params.getall("operator_products"):
        oproduct = models.SlcOperatorProducts()
        oproduct.operator_name = form.d.operator_name
        oproduct.product_id = product_id
        db.add(oproduct)

    # update rules
    db.query(models.SlcOperatorRule).filter_by(operator_name=opr.operator_name).delete()

    for path in request.params.getall("rule_item"):
        item = permit.get_route(path)
        if not item: continue
        rule = models.SlcOperatorRule()
        rule.operator_name = opr.operator_name
        rule.rule_name = item['name']
        rule.rule_path = item['path']
        rule.rule_category = item['category']
        db.add(rule)

    permit.unbind_opr(opr.operator_name)
    for rule in db.query(models.SlcOperatorRule).filter_by(operator_name=opr.operator_name):
        permit.bind_opr(rule.operator_name, rule.rule_path)

    ops_log = models.SlcRadOperateLog()
    ops_log.operator_name = get_cookie("username")
    ops_log.operate_ip = get_cookie("login_ip")
    ops_log.operate_time = utils.get_currtime()
    ops_log.operate_desc = u'操作员(%s)修改操作员信息:%s' % (get_cookie("username"), opr.operator_name)
    db.add(ops_log)

    db.commit()
    redirect("/opr")
Пример #3
0
def opr_update(db, render):
    opr_id = request.params.get("opr_id")
    opr = db.query(models.SlcOperator).get(opr_id)
    nodes = [(n.node_name, n.node_desc) for n in db.query(models.SlcNode)]
    products = [(str(p.id), p.product_name) for p in db.query(models.SlcRadProduct)]

    form = opr_forms.opr_update_form(nodes, products)
    form.fill(opr)
    form.operator_pass.set_value('')

    onodes = db.query(models.SlcOperatorNodes).filter_by(operator_name=form.d.operator_name)
    oproducts = db.query(models.SlcOperatorProducts).filter_by(operator_name=form.d.operator_name)

    form.operator_nodes.set_value([ond.node_name for ond in onodes])
    form.operator_products.set_value([str(p.product_id) for p in oproducts])
    rules = db.query(models.SlcOperatorRule.rule_path).filter_by(operator_name=opr.operator_name)
    rules = [r[0] for r in rules]
    return render("sys_opr_form", form=form, rules=rules)
Пример #4
0
def opr_update(db, render):
    opr_id = request.params.get("opr_id")
    opr = db.query(models.SlcOperator).get(opr_id)
    nodes = [(n.node_name, n.node_desc) for n in db.query(models.SlcNode)]
    products = [(str(p.id), p.product_name)
                for p in db.query(models.SlcRadProduct)]

    form = opr_forms.opr_update_form(nodes, products)
    form.fill(opr)
    form.operator_pass.set_value('')

    onodes = db.query(
        models.SlcOperatorNodes).filter_by(operator_name=form.d.operator_name)
    oproducts = db.query(models.SlcOperatorProducts).filter_by(
        operator_name=form.d.operator_name)

    form.operator_nodes.set_value([ond.node_name for ond in onodes])
    form.operator_products.set_value([str(p.product_id) for p in oproducts])
    rules = db.query(models.SlcOperatorRule.rule_path).filter_by(
        operator_name=opr.operator_name)
    rules = [r[0] for r in rules]
    return render("sys_opr_form", form=form, rules=rules)