- if sort:
- url_builder = lambda n: mark_safe("%s%s%s=%s&%s=%s" % (base_path, url_joiner, context.SORT, sort, context.PAGE, n))
- else:
- url_builder = lambda n: mark_safe("%s%s%s=%s" % (base_path, url_joiner, context.PAGE, n))
-
- if range_start > (context.outside_page_range + 1):
- page_numbers.append([(n, url_builder(n)) for n in range(1, context.outside_page_range + 1)])
- page_numbers.append(None)
- elif range_start > 1:
- page_numbers.append([(n, url_builder(n)) for n in range(1, range_start)])
-
- page_numbers.append([(n, url_builder(n)) for n in range(range_start, range_end + 1)])
-
- if range_end < (total_pages - context.outside_page_range):
- page_numbers.append(None)
- page_numbers.append([(n, url_builder(n)) for n in range(total_pages - context.outside_page_range + 1, total_pages + 1)])
- elif range_end < total_pages:
- page_numbers.append([(n, url_builder(n)) for n in range(range_end + 1, total_pages + 1)])
-
- return page_numbers_template.render(template.Context({
- 'has_previous': has_previous,
- 'previous_url': has_previous and url_builder(page - 1) or None,
- 'has_next': has_next,
- 'next_url': has_next and url_builder(page + 1) or None,
- 'current': page,
- 'page_numbers': page_numbers
- }))