示例#1
0
    def post(self):
        nodes = [(n.node_name, n.node_desc) for n in self.db.query(models.TrNode)]
        products = [(p.id,p.product_name) for p in self.db.query(models.TrProduct)]
        form = operator_form.operator_update_form(nodes,products)
        if not form.validates(source=self.get_params()):
            rules = self.db.query(models.TrOperatorRule.rule_path).filter_by(operator_name=form.d.operator_name)
            rules = [r[0] for r in rules]
            return self.render("base_form.html", form=form,rules=rules)
        operator = self.db.query(models.TrOperator).get(form.d.id)
        if form.d.operator_pass:
            operator.operator_pass = md5(form.d.operator_pass.encode()).hexdigest()
        operator.operator_desc = form.d.operator_desc
        operator.operator_status = form.d.operator_status

        self.db.query(models.TrOperatorNodes).filter_by(operator_name=operator.operator_name).delete()
        for node in self.get_arguments("operator_nodes"):
            onode = models.TrOperatorNodes()
            onode.operator_name = form.d.operator_name
            onode.node_name = node
            self.db.add(onode)

        self.db.query(models.TrOperatorProducts).filter_by(operator_name=operator.operator_name).delete()
        for product_id in self.get_arguments("operator_products"):
            oproduct = models.TrOperatorProducts()
            oproduct.operator_name = form.d.operator_name
            oproduct.product_id = product_id
            self.db.add(oproduct)

        self.add_oplog(u'修改操作员%s信息' % utils.safeunicode(operator.operator_name))

        # update rules
        self.db.query(models.TrOperatorRule).filter_by(operator_name=operator.operator_name).delete()

        for path in self.get_arguments("rule_item"):
            item = permit.get_route(path)
            if not item: continue
            rule = models.TrOperatorRule()
            rule.operator_name = operator.operator_name
            rule.rule_name = item['name']
            rule.rule_path = item['path']
            rule.rule_category = item['category']
            self.db.add(rule)

        permit.unbind_opr(operator.operator_name)

        self.db.commit()

        for rule in self.db.query(models.TrOperatorRule).filter_by(operator_name=operator.operator_name):
            permit.bind_opr(rule.operator_name, rule.rule_path)

        self.redirect("/admin/operator",permanent=False)
示例#2
0
    def post(self):
        nodes = [(n.node_name, n.node_desc) for n in self.db.query(models.TrNode)]
        products = [(p.id,p.product_name) for p in self.db.query(models.TrProduct)]
        form = operator_form.operator_update_form(nodes,products)
        if not form.validates(source=self.get_params()):
            rules = self.db.query(models.TrOperatorRule.rule_path).filter_by(operator_name=form.d.operator_name)
            rules = [r[0] for r in rules]
            return self.render("opr_form.html", form=form,rules=rules)
        operator = self.db.query(models.TrOperator).get(form.d.id)
        if form.d.operator_pass:
            operator.operator_pass = md5(form.d.operator_pass.encode()).hexdigest()
        operator.operator_desc = form.d.operator_desc
        operator.operator_status = form.d.operator_status

        self.db.query(models.TrOperatorNodes).filter_by(operator_name=operator.operator_name).delete()
        for node in self.get_arguments("operator_nodes"):
            onode = models.TrOperatorNodes()
            onode.operator_name = form.d.operator_name
            onode.node_name = node
            self.db.add(onode)

        self.db.query(models.TrOperatorProducts).filter_by(operator_name=operator.operator_name).delete()
        for product_id in self.get_arguments("operator_products"):
            oproduct = models.TrOperatorProducts()
            oproduct.operator_name = form.d.operator_name
            oproduct.product_id = product_id
            self.db.add(oproduct)

        self.add_oplog(u'修改操作员%s信息' % utils.safeunicode(operator.operator_name))

        # update rules
        self.db.query(models.TrOperatorRule).filter_by(operator_name=operator.operator_name).delete()

        for path in self.get_arguments("rule_item"):
            item = permit.get_route(path)
            if not item: continue
            rule = models.TrOperatorRule()
            rule.operator_name = operator.operator_name
            rule.rule_name = item['name']
            rule.rule_path = item['path']
            rule.rule_category = item['category']
            self.db.add(rule)

        permit.unbind_opr(operator.operator_name)

        self.db.commit()

        for rule in self.db.query(models.TrOperatorRule).filter_by(operator_name=operator.operator_name):
            permit.bind_opr(rule.operator_name, rule.rule_path)

        self.redirect("/admin/operator",permanent=False)
示例#3
0
    def post(self):
        form = operator_form.operator_update_form()
        if not form.validates(source=self.get_params()):
            rules = self.db.query(models.TrwOperatorRule.rule_path).filter_by(
                operator_name=form.d.operator_name)
            rules = [r[0] for r in rules]
            return self.render("base_form.html", form=form, rules=rules)
        operator = self.db.query(models.TrwOperator).get(form.d.id)
        if form.d.operator_pass:
            operator.operator_pass = md5(
                form.d.operator_pass.encode()).hexdigest()
        operator.operator_desc = form.d.operator_desc
        operator.operator_status = form.d.operator_status

        ops_log = models.TrwOperateLog()
        ops_log.operator_name = self.get_secure_cookie("tra_user")
        ops_log.operate_ip = self.get_secure_cookie("tra_login_ip")
        ops_log.operate_time = utils.get_currtime()
        ops_log.operate_desc = u'修改操作员%s信息' % operator.operator_name
        self.db.add(ops_log)

        # update rules
        self.db.query(models.TrwOperatorRule).filter_by(
            operator_name=operator.operator_name).delete()

        for path in self.get_arguments("rule_item"):
            item = permit.get_route(path)
            if not item: continue
            rule = models.TrwOperatorRule()
            rule.operator_name = operator.operator_name
            rule.rule_name = item['name']
            rule.rule_path = item['path']
            rule.rule_category = item['category']
            self.db.add(rule)

        permit.unbind_opr(operator.operator_name)

        self.db.commit()

        for rule in self.db.query(models.TrwOperatorRule).filter_by(
                operator_name=operator.operator_name):
            permit.bind_opr(rule.operator_name, rule.rule_path)

        self.redirect("/operator", permanent=False)
示例#4
0
    def post(self):
        form = operator_form.operator_update_form()
        if not form.validates(source=self.get_params()):
            rules = self.db.query(models.TrwOperatorRule.rule_path).filter_by(operator_name=form.d.operator_name)
            rules = [r[0] for r in rules]
            return self.render("base_form.html", form=form,rules=rules)
        operator = self.db.query(models.TrwOperator).get(form.d.id)
        if form.d.operator_pass:
            operator.operator_pass = md5(form.d.operator_pass.encode()).hexdigest()
        operator.operator_desc = form.d.operator_desc
        operator.operator_status = form.d.operator_status

        ops_log = models.TrwOperateLog()
        ops_log.operator_name = self.get_secure_cookie("tra_user")
        ops_log.operate_ip = self.get_secure_cookie("tra_login_ip")
        ops_log.operate_time = utils.get_currtime()
        ops_log.operate_desc = u'修改操作员%s信息' % operator.operator_name
        self.db.add(ops_log)

        # update rules
        self.db.query(models.TrwOperatorRule).filter_by(operator_name=operator.operator_name).delete()

        for path in self.get_arguments("rule_item"):
            item = permit.get_route(path)
            if not item: continue
            rule = models.TrwOperatorRule()
            rule.operator_name = operator.operator_name
            rule.rule_name = item['name']
            rule.rule_path = item['path']
            rule.rule_category = item['category']
            self.db.add(rule)

        permit.unbind_opr(operator.operator_name)

        self.db.commit()

        for rule in self.db.query(models.TrwOperatorRule).filter_by(operator_name=operator.operator_name):
            permit.bind_opr(rule.operator_name, rule.rule_path)

        self.redirect("/operator",permanent=False)
示例#5
0
    def post(self):
        form = operator_form.operator_add_form()
        if not form.validates(source=self.get_params()):
            return self.render("base_form.html", form=form)
        if self.db.query(models.TrwOperator.id).filter_by(
                operator_name=form.d.operator_name).count() > 0:
            return self.render("base_form.html", form=form, msg=u"操作员已经存在")
        operator = models.TrwOperator()
        operator.operator_name = form.d.operator_name
        operator.operator_pass = md5(form.d.operator_pass.encode()).hexdigest()
        operator.operator_type = 1
        operator.operator_desc = form.d.operator_desc
        operator.operator_status = form.d.operator_status
        self.db.add(operator)

        ops_log = models.TrwOperateLog()
        ops_log.operator_name = self.current_user.username
        ops_log.operate_ip = self.current_user.ipaddr
        ops_log.operate_time = utils.get_currtime()
        ops_log.operate_desc = u'新增操作员信息:%s' % operator.operator_name
        self.db.add(ops_log)

        for path in self.get_arguments("rule_item"):
            item = permit.get_route(path)
            if not item: continue
            rule = models.TrwOperatorRule()
            rule.operator_name = operator.operator_name
            rule.rule_name = item['name']
            rule.rule_path = item['path']
            rule.rule_category = item['category']
            self.db.add(rule)

        self.db.commit()

        for rule in self.db.query(models.TrwOperatorRule).filter_by(
                operator_name=operator.operator_name):
            permit.bind_opr(rule.operator_name, rule.rule_path)

        self.redirect("/operator", permanent=False)
示例#6
0
    def post(self):
        form = operator_form.operator_add_form()
        if not form.validates(source=self.get_params()):
            return self.render("base_form.html", form=form)
        if self.db.query(models.TrwOperator.id).filter_by(operator_name=form.d.operator_name).count() > 0:
            return self.render("base_form.html", form=form, msg=u"操作员已经存在")
        operator = models.TrwOperator()
        operator.operator_name = form.d.operator_name
        operator.operator_pass = md5(form.d.operator_pass.encode()).hexdigest()
        operator.operator_type = 1
        operator.operator_desc = form.d.operator_desc
        operator.operator_status = form.d.operator_status
        self.db.add(operator)

        ops_log = models.TrwOperateLog()
        ops_log.operator_name = self.current_user.username
        ops_log.operate_ip = self.current_user.ipaddr
        ops_log.operate_time = utils.get_currtime()
        ops_log.operate_desc = u'新增操作员信息:%s' % operator.operator_name
        self.db.add(ops_log)

        for path in self.get_arguments("rule_item"):
            item = permit.get_route(path)
            if not item: continue
            rule = models.TrwOperatorRule()
            rule.operator_name = operator.operator_name
            rule.rule_name = item['name']
            rule.rule_path = item['path']
            rule.rule_category = item['category']
            self.db.add(rule)

        self.db.commit()

        for rule in self.db.query(models.TrwOperatorRule).filter_by(operator_name=operator.operator_name):
            permit.bind_opr(rule.operator_name, rule.rule_path)

        self.redirect("/operator",permanent=False)