Пример #1
0
 def get(self):
     '''
     获取数据,如果有ID就是单个数据,没有就是全部数据
     '''
     args_id = parse_id.parse_args()
     id = args_id.get('id')
     if id:
         return {'status': RET.OK, 'data': object_to_json(getSingData(id))}
     list_by_menu = {}
     _list = []
     if g.admin.is_super == 0:
         # 如果不是超级管理员,只能在自己的权限范围内进行授权
         if not g.auth:
             abort(RET.BadRequest, msg='请勿非法操作')
         _list = g.auth
     else:
         _list = Rule.query.filter_by(is_del='0').all()
     if not _list:
         abort(RET.BadRequest, msg='暂无数据')
     for v in _list:
         if v.menu_id in list_by_menu.keys():
             list_by_menu[v.menu_id].append(object_to_json(v))
         else:
             list_by_menu[v.menu_id] = [object_to_json(v)]
     data = {'status': RET.OK, 'data': list_by_menu}
     return data
Пример #2
0
 def get(self):
     '''
     获取列表
     '''
     args = parse_page.parse_args()
     id = args.get('id')
     site = args.get('site')
     if id:
         return {'status': RET.OK, 'data': object_to_json(getSingData(id))}
     page = 1
     paginate = PAGINATE_NUM
     if args.get('page'):
         page = int(args.get('page'))
     if args.get('paginate'):
         paginate = int(args.get('paginate'))
     _list = Message.query.filter_by(is_del='0', site=site).order_by(
         Message.create_time.desc()).paginate(page, paginate, False)
     if not _list:
         abort(RET.BadRequest, msg='暂无数据')
     data = {
         'status': RET.OK,
         'paginate': {
             'page': _list.page,
             'per_page': _list.per_page,
             'total': _list.total
         },
         'data': [object_to_json(v) for v in _list.items]
     }
     return data
Пример #3
0
 def get(self):
     '''
     获取列表
     '''
     args_id = parse_id.parse_args()
     id = args_id.get('id')
     if id:
         return {'status': RET.OK, 'data': object_to_json(getSingData(id))}
     _list = AdSpace.query.filter_by(is_del='0').order_by(
         AdSpace.sort.desc()).all()
     if not _list:
         abort(RET.BadRequest, msg='暂无数据')
     data = {'status': RET.OK, 'data': [object_to_json(v) for v in _list]}
     return data
Пример #4
0
 def get(self):
     '''
     获取配置列表
     '''
     list_by_menu = {}
     _list = WebConfig.query.filter_by(is_del='0').order_by(
         WebConfig.sort.desc()).all()
     if not _list:
         abort(RET.BadRequest, msg='暂无数据')
     for v in _list:
         if v.site in list_by_menu.keys():
             list_by_menu[v.site].append(object_to_json(v))
         else:
             list_by_menu[v.site] = [object_to_json(v)]
     data = {'status': RET.OK, 'data': list_by_menu}
     return data
Пример #5
0
 def get(self):
     '''
     获取用户信息
     '''
     if g.user:
         data = {'status': RET.OK, 'data': object_to_json(g.user)}
         return data
     abort(RET.BadRequest, msg='请勿非法操作')
Пример #6
0
 def get(self):
     '''
     获取当前登录用户的信息
     '''
     if g.admin:
         data = {
                 'status':RET.OK,
                 'data':object_to_json(g.admin)
             }
         return data
     abort(RET.BadRequest,msg='请勿非法操作')
Пример #7
0
 def get(self):
     '''
     获取列表
     '''
     args_id = parse_id.parse_args()
     id = args_id.get('id')
     space_id = args_id.get('space_id')
     ename = args_id.get('ename')
     if id:
         return {'status': RET.OK, 'data': object_to_json(getSingData(id))}
     if space_id:
         _list = Ad.query.filter_by(is_del='0', space_id=space_id).order_by(
             Ad.sort.desc()).all()
         if not _list:
             abort(RET.BadRequest, msg='暂无数据')
         data = {
             'status': RET.OK,
             'data': [object_to_json(v) for v in _list]
         }
         return data
     if ename:
         sql = '''
             SELECT 
             a.name,a.info,a.url,a.img
             FROM ad as a
             left join ad_space as s on s.id = a.space_id
             WHERE a.is_del = 0
             AND s.ename = '%s'
             ORDER BY a.sort DESC;
         ''' % ename
         sql_data = Crud.auto_select(sql)
         if sql_data:
             fetchall_data = sql_data.fetchall()
             if not fetchall_data:
                 abort(RET.NotFound, msg='暂无数据')
             data = {
                 'status': RET.OK,
                 'data': ([mysql_to_json(dict(v)) for v in fetchall_data])
             }
             return data
     abort(RET.BadRequest, msg='暂无数据')
Пример #8
0
 def get(self, site):
     '''
     标签列表
     '''
     tagModel = setModel(site)
     tag_list = tagModel.query.filter_by(is_del='0').order_by(
         tagModel.sort.desc(), tagModel.create_time.desc()).all()
     if not tag_list:
         abort(RET.BadRequest, msg='暂无数据')
     data = {
         'status': RET.OK,
         'data': [object_to_json(v) for v in tag_list]
     }
     return data
Пример #9
0
    def get(self):
        '''
        获取用户信息
        '''
        args_id = parse_id.parse_args()
        id = args_id.get('id')
        if id:
            admin = get_admin(id)
            data = {
                        'status':RET.OK,
                        'data':object_to_json(admin)
                    }
            return data
        args = parse_page.parse_args()
        page = 1
        paginate = PAGINATE_NUM
        if args.get('page'):
            page = int(args.get('page'))
        if args.get('paginate'):
            paginate = int(args.get('paginate'))
        sql = '''
        SELECT SQL_CALC_FOUND_ROWS a.id,a.username,a.name,a.phone,a.email,
        GROUP_CONCAT(r.name SEPARATOR ',') as roles_name,
		GROUP_CONCAT(ar.role_id SEPARATOR ',') as roles,
        l.create_time as last_login,
        l.ip as ip
        FROM admin as a
        left join admin_role as ar on a.id = ar.admin_id
        left join role as r on r.id = ar.role_id
        left join admin_log as l on l.username = a.username and l.create_time=(select max(create_time) from admin_log where username=a.username)
        WHERE a.is_del = 0
        GROUP BY a.id
        LIMIT {0},{1};
        '''.format((page-1)*paginate,paginate)
        sql_data,count = Crud.auto_select(sql,count=True)
        if not sql_data:
            abort(RET.NotFound,msg='暂无数据')
        fetchall_data = sql_data.fetchall()
        data = {
                    'status':RET.OK,
                    'paginate':{
                        'page':page,
                        'per_page':paginate,
                        'total':count
                    },
                    'data':([mysql_to_json(dict(v))  for v in fetchall_data])
            }
        return data 
Пример #10
0
def build_tree(data, pid, level=0):
    """
    生成树
    :param data:    数据
    :param p_id:    上级分类
    :param level:   当前级别
    :return:
    """
    tree = []
    for v in data:
        row = object_to_json(v)
        if row:
            if row['pid'] == pid:
                row['level'] = level
                child = build_tree(data, row['id'], level + 1)
                row['children'] = []
                if child:
                    row['children'] += child
                tree.append(row)
    return tree
Пример #11
0
 def get(self,site):
     '''
     获取分类树
     '''
     categoryModel = setModel(site)
     args = parse_id.parse_args()
     id = args.get('id')
     if  id:
         return {
                 'status':RET.OK,
                 'data':object_to_json(getCategory(id,categoryModel))
         } 
     cate_list = categoryModel.query.filter_by(is_del = '0').order_by(categoryModel.sort.desc()).all()
     if not cate_list:
         abort(RET.BadRequest,msg='暂无数据')
     data = {
                 'status':RET.OK,
                 'data':build_tree(cate_list,'0',0)
         }
     return data 
Пример #12
0
 def get(self):
     '''
     获取菜单树
     '''
     args_id = parse_id.parse_args()
     id = args_id.get('id')
     if id:
         return {
                     'status':RET.OK,
                     'data':object_to_json(getSingData(id))
             } 
     _list = Menu.query.filter_by(is_del = '0').order_by(Menu.sort.desc()).all()
     if not _list:
         abort(RET.BadRequest,msg='暂无数据')
     if g.admin.is_super==0:
         authMenus = getParent(_list,[v for v in _list if v.id in g.menus])
         _list = authMenus
     data = {
                 'status':RET.OK,
                 'data':build_tree(_list,'0',0)
         }
     return data  
Пример #13
0
 def get(self):
     '''
     获取数据,如果有ID就是单个数据,没有就是全部数据
     '''
     args_id = parse_id.parse_args()
     id = args_id.get('id')
     if id:
         sql = '''
         SELECT j.*,GROUP_CONCAT(r.rule_id SEPARATOR ',') as rules
         FROM role as j
         left join role_rule as r on j.id = r.role_id
         WHERE j.is_del = 0 AND j.id = %s
         ''' % id
         sql_data = Crud.auto_select(sql)
         first_data = sql_data.first()
         if not first_data:
             abort(RET.NotFound, msg='角色不存在')
         return {'status': RET.OK, 'data': mysql_to_json(dict(first_data))}
     _list = Role.query.filter_by(is_del='0').all()
     if not _list:
         abort(RET.BadRequest, msg='暂无数据')
     data = {'status': RET.OK, 'data': [object_to_json(v) for v in _list]}
     return data