Exemplo n.º 1
0
    def get(self):
        search_value = self.get_argument('search_value', '')
        search_type = self.get_argument('search_type', '')
        page = int(self.get_argument('page', 1))
        if page <= 0: page = 1

        limit = int(self.get_argument('limit', 10))
        if limit <= 0 or limit >= 100: limit = 10

        Q = {}
        if search_value and search_type in ['title', '_id']:
            if search_type == '_id':
                Q[search_type] = ObjectId(search_value)
            else:
                Q[search_type] = {'$regex': search_value}

        _list = tb_anime.find(Q).sort('atime', -1).limit(limit).skip(
            (page - 1) * limit)
        count = tb_anime.find(Q).count()

        res = []
        for f in _list:
            f['atime'] = str(cp.unixtimeToDatetime(f.get('atime', 0)))
            res.append(cp.formatWriteJson(f))

        self.write({
            'code': 0,
            'msg': 'ok',
            'count': count,
            'data': res,
        })
Exemplo n.º 2
0
    def get(self):
        search_value = self.get_argument('search_value', '')
        search_type = self.get_argument('search_type', '')
        page = int(self.get_argument('page', 1))
        if page <= 0: page = 1

        limit = int(self.get_argument('limit', 10))
        if limit <= 0 or limit >= 100: limit = 10

        Q = {}
        if search_value and search_type in ['title', '_id', 'anime_id']:
            if search_type in ['_id', 'anime_id']:
                Q[search_type] = ObjectId(search_value)
            else:
                Q[search_type] = {'$regex': search_value}

        _list = tb_music.find(Q).sort('atime', -1).limit(limit).skip(
            (page - 1) * limit)
        count = tb_music.find(Q).count()

        res = []
        for f in _list:
            f['play_url'] = GetSignUrl(str(f['_id']))
            anime_info = tb_anime.find_one({'_id': f.get('anime_id', None)})
            if anime_info:
                f['anime_name'] = anime_info.get('title')
            else:
                f['anime_name'] = '未知'
            f['atime'] = str(cp.unixtimeToDatetime(f['atime']))
            res.append(cp.formatWriteJson(f))

        self.write({
            'code': 0,
            'msg': 'ok',
            'count': count,
            'data': res,
        })