async def list_users(request): page = request.GET.get('page', 0) page_size = 50 total_cnt = User.count() num_pages = total_cnt / page_size + 1 users = [ x for x in User.find({}, skip=page * page_size, limit=page_size, sort=[('last_request_time', -1)]) ] return aiohttp_jinja2.render_template('users.html', request, { 'users': users, 'num_pages': num_pages, })
async def list_users(request): page = request.GET.get('page', 0) page_size = 50 total_cnt = User.count() now = datetime.datetime.now() week_ago = now - datetime.timedelta(days=7) month_ago = now - datetime.timedelta(days=30) weekly_active = User.count({'last_request_time': {'$gte': week_ago}}) monthly_active = User.count({'last_request_time': {'$gte': month_ago}}) num_pages = total_cnt / page_size + 1 all_users = User.find({}, skip=page*page_size, limit=page_size, sort=[('last_request_time', -1)]) users = [x for x in all_users] return aiohttp_jinja2.render_template( 'users.html', request, { 'users': users, 'num_pages': num_pages, 'total': total_cnt, 'monthly_active': monthly_active, 'weekly_active': weekly_active, } )