# 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/manage/resource/template_forms.py
# def tpl_add_form():
# def tpl_update_form():
# 
# 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):


import cyclone.web
from toughwlan.manage.base import BaseHandler, MenuRes
from toughlib.permit import permit
from toughwlan.manage.resource import template_forms
from toughwlan import models
@permit.route(r"/template", u"认证模版管理", MenuRes, order=7.0000, is_menu=True)
class TemplateHandler(BaseHandler):
    @cyclone.web.authenticated
    def get(self):
        tpl_list = self.db.query(models.TrwTemplate)
        self.render("template.html",tpl_list=tpl_list)


@permit.route(r"/template/add", u"模版新增", MenuRes, order=7.0001)
class TemplateAddHandler(BaseHandler):
    @cyclone.web.authenticated
    def get(self):
        form = template_forms.tpl_add_form()
        self.render("base_form.html", form=form)

    @cyclone.web.authenticated
    def post(self, *args, **kwargs):
        form = template_forms.tpl_add_form()
        if not form.validates(source=self.get_params()):
            return self.render("base_form.html", form=form)

        tpl = models.TrwTemplate()
        tpl.tpl_name = form.d.tpl_name
        tpl.tpl_desc = form.d.tpl_desc
        self.db.add(tpl)

        self.db.commit()
        self.redirect("/template")



# 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/manage/resource/template_forms.py
# def tpl_add_form():
# def tpl_update_form():
# 
# 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/resource/template.py
import cyclone.web
from toughwlan.manage.base import BaseHandler, MenuRes
from toughlib.permit import permit
from toughwlan.manage.resource import template_forms
from toughwlan import models

@permit.route(r"/template", u"认证模版管理", MenuRes, order=7.0000, is_menu=True)
class TemplateHandler(BaseHandler):
    @cyclone.web.authenticated
    def get(self):
        tpl_list = self.db.query(models.TrwTemplate)
        self.render("template.html",tpl_list=tpl_list)


@permit.route(r"/template/add", u"模版新增", MenuRes, order=7.0001)
class TemplateAddHandler(BaseHandler):
    @cyclone.web.authenticated
    def get(self):
        form = template_forms.tpl_add_form()
        self.render("base_form.html", form=form)

    @cyclone.web.authenticated
    def post(self, *args, **kwargs):
        form = template_forms.tpl_add_form()
        if not form.validates(source=self.get_params()):
            return self.render("base_form.html", form=form)

        tpl = models.TrwTemplate()
        tpl.tpl_name = form.d.tpl_name
        tpl.tpl_desc = form.d.tpl_desc
        self.db.add(tpl)

        self.db.commit()
        self.redirect("/template")



@permit.route(r"/template/update", u"模版修改", MenuRes, order=7.0002)