# 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 json
import re
import time
import urlparse
import urllib
import traceback
import functools
import cyclone.web
from mako.template import Template
from cyclone.util import ObjectDict
from twisted.internet import defer
from toughlib import utils, apiutils
from toughlib import dispatch, logger
from toughwlan import models
from toughlib import db_session as session
from toughwlan.manage.settings import *
            tpl_name = tpl_name or "default"
            tpl_dict = dict(
                isp_code=ispcode,
                tpl_path=tpl_name,
                ssid=ssid,
                domain=domain_code
            )
            dmattrs = self.db.query(models.TrwDomainAttr).filter_by(
                domain_code=domain_code,isp_code=ispcode)
            for dattr in dmattrs:
                tpl_dict[dattr.attr_name] = dattr.attr_value
            return tpl_dict

        return self.cache.aget(template_cache_key(ssid, ispcode),fetch_result,expire=3600)

    def get_nas(self, ipaddr):
        def fetch_result():
            nas = self.db.query(models.TrwBas).filter_by(ip_addr=ipaddr).first()
            return nas and { c.name:getattr(nas, c.name)  for c in nas.__table__.columns} or {}
        return self.cache.aget(nas_cache_ipkey(ipaddr),fetch_result,expire=3600)

    def get_domain(self, ssid, ispcode):
        def fetch_result():
            return self.db.query(models.TrwSsid.domain_code).filter_by(
                ssid=ssid, isp_code=ispcode).scalar()
        return self.cache.aget(domain_cache_key(ssid, ispcode),fetch_result,expire=3600)

        
    def get_check_os_funs(self):
        def fetch_result():

# 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/portal/base.py
import json
import re
import time
import urlparse
import urllib
import traceback
import functools
import cyclone.web
from mako.template import Template
from cyclone.util import ObjectDict
from twisted.internet import defer
from toughlib import utils, apiutils
from toughlib import dispatch, logger
from toughwlan import models
from toughlib import db_session as session
from toughwlan.manage.settings import *

            tpl_name = tpl_name or "default"
            tpl_dict = dict(
                isp_code=ispcode,
                tpl_path=tpl_name,
                ssid=ssid,
                domain=domain_code
            )
            dmattrs = self.db.query(models.TrwDomainAttr).filter_by(
                domain_code=domain_code,isp_code=ispcode)
            for dattr in dmattrs:
                tpl_dict[dattr.attr_name] = dattr.attr_value
            return tpl_dict

        return self.cache.aget(template_cache_key(ssid, ispcode),fetch_result,expire=3600)

    def get_nas(self, ipaddr):
        def fetch_result():
            nas = self.db.query(models.TrwBas).filter_by(ip_addr=ipaddr).first()
            return nas and { c.name:getattr(nas, c.name)  for c in nas.__table__.columns} or {}
        return self.cache.aget(nas_cache_ipkey(ipaddr),fetch_result,expire=3600)

    def get_domain(self, ssid, ispcode):
        def fetch_result():
            return self.db.query(models.TrwSsid.domain_code).filter_by(
                ssid=ssid, isp_code=ispcode).scalar()
        return self.cache.aget(domain_cache_key(ssid, ispcode),fetch_result,expire=3600)

        
    def get_check_os_funs(self):
        def fetch_result():

            ostypes = [(it.os_name, it.dev_type, it.match_rule) for it in self.db.query(models.TrwOSTypes)]