$def with (page, num_found, results_per_page=20) $ pages = ceil(num_found / results_per_page) $if pages != 1: $ pages_in_set = 10 $ half = pages_in_set // 2 $if pages < pages_in_set: $ first_page_in_set = 1 $ last_page_in_set = pages $elif page < half: $ first_page_in_set = 1 $ last_page_in_set = min((pages_in_set, pages)) $elif page > (pages-half): $ first_page_in_set = max((pages-pages_in_set, 1)) $ last_page_in_set = pages $else: $ first_page_in_set = max((page-half, 1)) $ last_page_in_set = page+half
$if page != 1: « $_('First') < $_('Previous') $for p in range(first_page_in_set, last_page_in_set+1): $if p == page: $p $else: $p $if last_page_in_set != pages: $if last_page_in_set != pages-1: ... $pages $if page < pages: $_('Next') >