def get_statisic_list(): ref = f"{db_name}/{date}" pagination = Pagination(ref, **request.args)() items = (db.child(ref).order_by_key().start_at( pagination.start).limit_to_first(pagination.page_size).get()) last = next(reversed(items.val())) response = ResultSet(items.val(), pagination, last).response() return response
def test_middle2(self): pagination = Pagination(items_count=14, items_per_page=5, current_page=2, show_pages_count=5) assert pagination.total_pages_count == 3 assert pagination.current_page == 2 assert pagination.show_pages_count == 5 assert pagination.available_pages == [1, 2, 3] assert pagination.prev_page == 1 assert pagination.next_page == 3
def test_middle(self): pagination = Pagination(items_count=201, items_per_page=5, current_page=33, show_pages_count=5) assert pagination.total_pages_count == 41 assert pagination.current_page == 33 assert pagination.show_pages_count == 5 assert pagination.available_pages == [31, 32, 33, 34, 35] assert pagination.prev_page == 32 assert pagination.next_page == 34
def test_beginning2(self): pagination = Pagination(items_count=15, items_per_page=5, current_page=1, show_pages_count=5) assert pagination.total_pages_count == 3 assert pagination.current_page == 1 assert pagination.show_pages_count == 5 assert pagination.available_pages == [1, 2, 3] assert pagination.prev_page is None assert pagination.next_page == 2
def test_end(self): pagination = Pagination(items_count=199, items_per_page=5, current_page=40, show_pages_count=5) assert pagination.total_pages_count == 40 assert pagination.current_page == 40 assert pagination.show_pages_count == 5 assert pagination.available_pages == [36, 37, 38, 39, 40] assert pagination.prev_page == 39 assert pagination.next_page is None
def homepage(): page_number = request.args.get('page', default=1, type=int) api = CachedApi() all_categories = api.fetch_all_categories() pagination = Pagination(len(all_categories.categories), CATEGORY_PER_HOMEPAGE, page_number) offset = (pagination.current_page - 1) * CATEGORY_PER_HOMEPAGE limit = CATEGORY_PER_HOMEPAGE categories = all_categories.categories[offset:offset + limit + 1] return render_template('categories.html', all_categories=all_categories, categories=categories, pagination=pagination)
def category_page(category_id): page_number = request.args.get('page', default=1, type=int) api = CachedApi() all_categories = api.fetch_all_categories() product_count = api.fetch_product_count(category_id) pagination = Pagination(product_count, PRODUCTS_PER_CATEGORY_PAGE, page_number) products = api.fetch_products(category_id, offset=(pagination.current_page - 1) * PRODUCTS_PER_CATEGORY_PAGE, limit=PRODUCTS_PER_CATEGORY_PAGE) category = api.fetch_category(category_id) return render_template( 'category.html', all_categories=all_categories, category=category, product_short_description_length=PRODUCT_SHORT_DESCRIPTION_LENGTH, products=products, pagination=pagination)
def test_page_out_of_range2(self): pagination = Pagination(items_count=13, items_per_page=5, current_page=0, show_pages_count=5) assert pagination.current_page == 1