def get(self, *args, **kwargs): menu_id = self.get_argument('menu_id', default=None, strip=True) nav = self.get_argument('nav', default=None, strip=True) mlist = [] rlist = [] user_id = self.get_current_id() if nav == 'list': menu_name = 'name' else: menu_name = 'title' with DBContext('readonly') as session: my_roles = session.query(RoleMenus.menu_id).outerjoin( UserRoles, RoleMenus.role_id == UserRoles.role_id).filter( UserRoles.user_id == user_id).all() for r in my_roles: rlist.append(int(r[0])) all_menu = session.query(Menu).order_by(Menu.sort).all() for m in all_menu: data_dict = model_to_dict(m) if m.id in rlist or self.is_superuser(): data_dict.pop('ctime') mlist.append(data_dict) elif nav == 'list': data_dict.pop('ctime') mlist.append(data_dict) def getchildren(id=0): sz = [] for obj in mlist: if obj["pid"] == id: sz.append({ "id": obj["id"], "pid": obj["pid"], menu_name: obj["title"], "font": obj["font"], "icon": obj["icon"], "url": obj["url"], "spread": obj["spread"], "sort": obj["sort"], "children": getchildren(obj["id"]) }) return sz if menu_id: mlist = [] for m in all_menu: data_dict = model_to_dict(m) if m.id == int(menu_id): data_dict.pop('ctime') mlist.append(data_dict) self.write(dict(code=0, msg='成功', data=mlist)) return self.write(dict(code=0, msg='成功', data=getchildren())) return
def get(self, role_id): role_list = [] data_dict = {} with DBContext('readonly') as session: count = session.query(Roles).filter(Roles.status != '10').count() role_info = session.query( Roles, UserRoles.user_id, Users.username, Users.nickname).outerjoin( UserRoles, Roles.role_id == UserRoles.role_id).outerjoin( Users, Users.user_id == UserRoles.user_id).order_by( Roles.role_id) for i in role_info: data_dict = model_to_dict(i[0]) data_dict['ctime'] = str(data_dict['ctime']) data_dict['user_id'] = i[1] data_dict['username'] = i[2] data_dict['nickname'] = i[3] role_list.append(data_dict) kargs = { "data": role_list, "count": 1000, "code": 0, } self.write(kargs)
def get(self, *args, **kwargs): page_size = self.get_argument('page', default=1, strip=True) limit = self.get_argument('limit', default=10, strip=True) username = self.get_argument('username', default=None, strip=True) limit_start = (int(page_size) - 1) * int(limit) user_list = [] with DBContext('readonly') as session: count = session.query(Users).filter(Users.status != '10').count() user_info = session.query(Users).filter( Users.status != '10').order_by( Users.user_id).offset(limit_start).limit(int(limit)) if username: user_info = session.query(Users).filter( Users.status != '10', Users.username.like(username + '%')).order_by( Users.user_id).offset(limit_start).limit(int(limit)) for msg in user_info: data_dict = model_to_dict(msg) data_dict.pop('password') data_dict.pop('google_key') data_dict['last_login'] = str(data_dict['last_login']) data_dict['ctime'] = str(data_dict['ctime']) user_list.append(data_dict) kwargs = { "data": user_list, "code": 0, "count": count, "msg": '获取用户成功' } self.write(kwargs)
def get(self, *args, **kwargs): page_size = self.get_argument('page', default=1, strip=True) limit = self.get_argument('limit', default=10, strip=True) role_name = self.get_argument('role_name', default=None, strip=True) limit_start = (int(page_size) - 1) * int(limit) role_list = [] with DBContext('readonly') as session: count = session.query(Roles).filter(Roles.status != '10').count() role_info = session.query(Roles).filter( Roles.status != '10').order_by( Roles.role_id).offset(limit_start).limit(int(limit)) if role_name: role_info = session.query(Roles).filter( Roles.status != '10', Roles.role_name.like(role_name + '%')).order_by( Roles.role_id).offset(limit_start).limit(int(limit)) for msg in role_info: data_dict = model_to_dict(msg) data_dict['ctime'] = str(data_dict['ctime']) role_list.append(data_dict) kwargs = { "data": role_list, "code": 0, "count": count, "msg": '获取角色成功' } self.write(kwargs)
def get(self, *args, **kwargs): page_size = self.get_argument('page', default=1, strip=True) limit = self.get_argument('limit', default=10, strip=True) username = self.get_argument('username', default=None, strip=True) ctime = self.get_argument('ctime', default='2017-12-15 00:00:00', strip=True) time_tuple = time.strptime(ctime, '%Y-%m-%d %H:%M:%S') limit_start = (int(page_size) - 1) * int(limit) log_list = [] with DBContext('readonly') as session: count = session.query(OperationRecord).count() log_info = session.query(OperationRecord).filter( OperationRecord.ctime > time_tuple).order_by( -OperationRecord.ctime).offset(limit_start).limit( int(limit)) if username: count = session.query(OperationRecord).filter( OperationRecord.ctime > time_tuple, OperationRecord.username.like(username + '%')).count() log_info = session.query(OperationRecord).filter( OperationRecord.ctime > time_tuple, OperationRecord.username.like(username + '%')).order_by( -OperationRecord.ctime).offset(limit_start).limit( int(limit)) for msg in log_info: data_dict = model_to_dict(msg) data_dict['ctime'] = str(data_dict['ctime']) log_list.append(data_dict) kwargs = {"data": log_list, "code": 0, "count": count, "msg": '获取成功'} self.write(kwargs)
def get(self, *args, **kwargs): func_list = [] with DBContext('readonly') as session: func_info = session.query(Functions).filter( Functions.status != '10').order_by(Functions.func_id).all() for msg in func_info: func_list.append(model_to_dict(msg)) self.write(dict(status=0, data=func_list))