# Path: handlers/base.py
# class BaseHandler(tornado.web.RequestHandler):
#     def __init__(self, application, request, **kwargs):
#         super(BaseHandler, self).__init__(application, request, **kwargs)
#         self.session = DB_Session()
# 
#     def data_received(self, chunk):
#         pass
# 
#     def get_current_user(self):
#         return self.get_secure_cookie("username")
# 
#     def on_finish(self):
#         self.session.close()
# 
# Path: models/models.py
# class DeviceGroup(BaseModel):
#     __tablename__ = 'deviceGroup'
# 
#     id = Column(Integer, Sequence('deviceGroup_id_seq'), primary_key=True)  # id
#     name = Column(String(32))  # 设备组名称
#     company_id = Column(Integer, ForeignKey('company.id'))  # 外键  公司
#     device_time_switch_id = Column(Integer, ForeignKey('device_timeSwitch.id'))  # 外键  公司
#     resGroup_id = Column(Integer, ForeignKey('resGroup.id'))  # 外键  资源组
#     device = relationship("Device", backref="deviceGroup")  # 对应设备
#     userGroup = relationship('UserGroup', secondary=userGroup_deviceGroup, back_populates='deviceGroup')


import tornado
import tornado.auth
import tornado.web
from handlers.base import BaseHandler
from models.models import DeviceGroup
#!/usr/bin/env python
# _*_coding:utf-8_*_



class IndexHandler(BaseHandler):

    @tornado.web.authenticated
    def get(self):

# Path: handlers/base.py
# class BaseHandler(tornado.web.RequestHandler):
#     def __init__(self, application, request, **kwargs):
#         super(BaseHandler, self).__init__(application, request, **kwargs)
#         self.session = DB_Session()
# 
#     def data_received(self, chunk):
#         pass
# 
#     def get_current_user(self):
#         return self.get_secure_cookie("username")
# 
#     def on_finish(self):
#         self.session.close()
# 
# Path: models/models.py
# class DeviceGroup(BaseModel):
#     __tablename__ = 'deviceGroup'
# 
#     id = Column(Integer, Sequence('deviceGroup_id_seq'), primary_key=True)  # id
#     name = Column(String(32))  # 设备组名称
#     company_id = Column(Integer, ForeignKey('company.id'))  # 外键  公司
#     device_time_switch_id = Column(Integer, ForeignKey('device_timeSwitch.id'))  # 外键  公司
#     resGroup_id = Column(Integer, ForeignKey('resGroup.id'))  # 外键  资源组
#     device = relationship("Device", backref="deviceGroup")  # 对应设备
#     userGroup = relationship('UserGroup', secondary=userGroup_deviceGroup, back_populates='deviceGroup')


# Path: handlers/index.py
import tornado
import tornado.auth
import tornado.web
from handlers.base import BaseHandler
from models.models import DeviceGroup

#!/usr/bin/env python
# _*_coding:utf-8_*_



class IndexHandler(BaseHandler):

    @tornado.web.authenticated
    def get(self):

        device_groups = self.session.query(DeviceGroup).filter(DeviceGroup.company_id == self.get_secure_cookie('company_id')).all()