async def api_get_items_v2(table, *, page='1', size='10'): models = {'users': User, 'blogs': Blog, 'comments': Comment} num = await models[table].countRows() page = Page(num, set_valid_value(page), set_valid_value(size, 10)) if num == 0: return dict(page=page, items=[]) items = await models[table].findAll(orderBy='created_at desc', limit=(page.offset, page.limit + num % page.limit)) return dict(page=page, items=[item.to_json(encrypted=True) for item in items])
async def index(*, tag='', page='1', size='10'): num = await Blog.countRows(where="position(? in `summary`)", args=[tag]) page = Page(num, set_valid_value(page), set_valid_value(size, 10)) if num == 0: blogs = [] else: blogs = await Blog.findAll("position(? in `summary`)", [tag], orderBy='created_at desc', limit=(page.offset, page.limit)) return { '__template__': 'uk-blogs.html', 'blogs': blogs, 'page': page, 'tag': tag }
async def api_get_items(table, *, page='1', size='10'): models = { 'users': User, 'blogs': Blog, 'comments': Comment, 'oauth': Oauth } num = await models[table].countRows() page = Page(num, set_valid_value(page), set_valid_value(size, 10)) if num == 0: return dict(page=page, items=[]) items = await models[table].findAll(orderBy='created_at desc', limit=(page.offset, page.limit + num % page.limit)) if table == 'users': for user in items: user.password = '******' return dict(page=page, items=items)