# Path: toughwlan/manage/base.py
# ADMIN_MENUS = (MenuSys, MenuRes, MenuUser) = (u"系统管理", u"资源管理", u"用户管理")
# MENU_ICONS = {
#     u"系统管理": "fa fa-cog",
#     u"资源管理": "fa fa-desktop",
#     u"用户管理": "fa fa-users"
# }
# class BaseHandler(cyclone.web.RequestHandler):
#     def __init__(self, *argc, **argkw):
#     def initialize(self):
#     def on_finish(self):
#     def get_error_html(self, status_code=500, **kwargs):
#     def render(self, template_name, **template_vars):
#     def render_error(self, **template_vars):
#     def render_json(self, **template_vars):
#     def render_string(self, template_name, **template_vars):
#     def render_from_string(self, template_string, **template_vars):
#     def get_page_data(self, query):
#     def get_page_url(self, page, form_id=None):
#     def set_session_user(self, username, ipaddr, opr_type, login_time):
#     def clear_session(self):
#     def get_current_user(self):
#     def get_params(self):
#     def get_params_obj(self, obj):
#     def add_oplog(self,message):
# 
# Path: toughwlan/models.py
# def get_metadata(db_engine):
# class SystemSession(DeclarativeBase):
# class SystemCache(DeclarativeBase):
# class TrwOperator(DeclarativeBase):
# class TrwOperatorRule(DeclarativeBase):
# class TrwParam(DeclarativeBase):
# class TrwIsp(DeclarativeBase):
# class TrwIspService(DeclarativeBase):
# class TrwBas(DeclarativeBase):
# class TrwDomain(DeclarativeBase):
# class TrwDomainAttr(DeclarativeBase):
# class TrwSsid(DeclarativeBase):
# class TrwRadius(DeclarativeBase):
# class TrwTemplate(DeclarativeBase):
# class TrwOperateLog(DeclarativeBase):
# class TrwOSTypes(DeclarativeBase):
# 
# Path: toughwlan/manage/system/operator_form.py
# def operator_add_form():
# def operator_update_form():
# 
# Path: toughwlan/manage/system/operator_form.py
# def operator_add_form():
# def operator_update_form():


from hashlib import md5
from toughlib import utils
from toughwlan.manage.base import BaseHandler, MenuSys
from toughlib.permit import permit
from toughwlan import models
from toughwlan.manage.system import operator_form
from toughwlan.manage.system.operator_form import opr_status_dict
import cyclone.web
        opr = self.db.query(models.TrwOperator).get(operator_id)
        form = operator_form.operator_update_form()
        form.fill(self.db.query(models.TrwOperator).get(operator_id))
        form.operator_pass.set_value('')
        rules = self.db.query(models.TrwOperatorRule.rule_path).filter_by(operator_name=opr.operator_name)
        rules = [r[0] for r in rules]
        return self.render("opr_form.html", form=form, rules=rules)

    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()


# Path: toughwlan/manage/base.py
# ADMIN_MENUS = (MenuSys, MenuRes, MenuUser) = (u"系统管理", u"资源管理", u"用户管理")
# MENU_ICONS = {
#     u"系统管理": "fa fa-cog",
#     u"资源管理": "fa fa-desktop",
#     u"用户管理": "fa fa-users"
# }
# class BaseHandler(cyclone.web.RequestHandler):
#     def __init__(self, *argc, **argkw):
#     def initialize(self):
#     def on_finish(self):
#     def get_error_html(self, status_code=500, **kwargs):
#     def render(self, template_name, **template_vars):
#     def render_error(self, **template_vars):
#     def render_json(self, **template_vars):
#     def render_string(self, template_name, **template_vars):
#     def render_from_string(self, template_string, **template_vars):
#     def get_page_data(self, query):
#     def get_page_url(self, page, form_id=None):
#     def set_session_user(self, username, ipaddr, opr_type, login_time):
#     def clear_session(self):
#     def get_current_user(self):
#     def get_params(self):
#     def get_params_obj(self, obj):
#     def add_oplog(self,message):
# 
# Path: toughwlan/models.py
# def get_metadata(db_engine):
# class SystemSession(DeclarativeBase):
# class SystemCache(DeclarativeBase):
# class TrwOperator(DeclarativeBase):
# class TrwOperatorRule(DeclarativeBase):
# class TrwParam(DeclarativeBase):
# class TrwIsp(DeclarativeBase):
# class TrwIspService(DeclarativeBase):
# class TrwBas(DeclarativeBase):
# class TrwDomain(DeclarativeBase):
# class TrwDomainAttr(DeclarativeBase):
# class TrwSsid(DeclarativeBase):
# class TrwRadius(DeclarativeBase):
# class TrwTemplate(DeclarativeBase):
# class TrwOperateLog(DeclarativeBase):
# class TrwOSTypes(DeclarativeBase):
# 
# Path: toughwlan/manage/system/operator_form.py
# def operator_add_form():
# def operator_update_form():
# 
# Path: toughwlan/manage/system/operator_form.py
# def operator_add_form():
# def operator_update_form():


# Path: toughwlan/manage/system/operator.py
from hashlib import md5
from toughlib import utils
from toughwlan.manage.base import BaseHandler, MenuSys
from toughlib.permit import permit
from toughwlan import models
from toughwlan.manage.system import operator_form
from toughwlan.manage.system.operator_form import opr_status_dict
import cyclone.web

        opr = self.db.query(models.TrwOperator).get(operator_id)
        form = operator_form.operator_update_form()
        form.fill(self.db.query(models.TrwOperator).get(operator_id))
        form.operator_pass.set_value('')
        rules = self.db.query(models.TrwOperatorRule.rule_path).filter_by(operator_name=opr.operator_name)
        rules = [r[0] for r in rules]
        return self.render("opr_form.html", form=form, rules=rules)

    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"):