Example #1
0
 def get(self):
     '''
     SHOW的留言和回复
     '''
     args = parse_page.parse_args()
     site = args.get('site')
     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.with_entities(
         Message.name, Message.info, Message.create_time, Message.reply,
         Message.update_time, Message.last_editor).filter_by(
             is_del='0', site=site,
             show='1').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': [mysql_to_json(v) for v in _list.items]
     }
     return data
Example #2
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 
Example #3
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='暂无数据')
Example #4
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
Example #5
0
 def get(self, site):
     '''
     内容列表1
     '''
     contentModel, contentTagModel, categoryModel, contentTable, contentTagTable, TagTable, categoryTable = setModel(
         site)
     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'))
     tag = args.get('tag')
     category_id = args.get('category_id')
     search = args.get('search')
     if search:
         current_app.logger.info(request.remote_addr + ':' + search)
     # 开始拼接查询语句
     query = '{0}{1}{2}'.format(
         ('t.name = "%s" and ' % tag) if tag else '',
         ('(a.id = "{0}" OR a.pid = "{0}") and '.format(category_id))
         if category_id else '',
         ('(c.title like "%{0}%" or c.content like "%{0}%") and '.format(
             search)) if search else '')
     # 分页大于=1000时,返回全部数据
     limit = 'LIMIT {0},{1}'.format((page - 1) * paginate, paginate)
     sql = '''
         SELECT 
         SQL_CALC_FOUND_ROWS c.*,
         GROUP_CONCAT(t.id SEPARATOR ',') as tags,
         GROUP_CONCAT(t.name SEPARATOR ',') as tags_name,
         a.name as category_name,
         a.module as module,
         a.icon as category_icon
         FROM {0} as c
         left join {1} as r on c.id = r.content_id
         left join {2} as t on t.id = r.tag_id
         left join {3} as a on a.id = c.category_id
         WHERE {4} c.is_del = 0
         GROUP BY c.id
         ORDER BY c.sort DESC,c.create_time DESC
         {5};
     '''.format(contentTable, contentTagTable, TagTable, categoryTable,
                query, limit)
     sql_data, count = Crud.auto_select(sql, count=True)
     if sql_data:
         fetchall_data = sql_data.fetchall()
         if not fetchall_data:
             abort(RET.NotFound, msg='暂无数据')
         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
     abort(RET.NotFound, msg='None data')