Skip to content

Commit

Permalink
Made it more readable.
Browse files Browse the repository at this point in the history
  • Loading branch information
kristofclaes committed Jun 25, 2015
1 parent eaf3712 commit 21d0114
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/django_ajax/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,33 +128,24 @@ def paginate(request,

# Page number?
page_num = request.GET.get(page_variable, None)
number_of_pages = paginator.num_pages

if page_num:
try:
page_num = int(page_num)
page_num = max(page_num, 1) # Make sure page number isn't negative
page_num = max(page_num, 1) # Make sure page number isn't negative.
page_num = min(page_num, number_of_pages) # Make sure the pagenumber isn't bigger than the number of pages.
except ValueError:
page_num = 1
else:
# Default start page
if default_to_last_page:
page_num = paginator.num_pages
page_num = number_of_pages
else:
page_num = 1

# Make sure the pagenumber isn't bigger than the number of pages.
number_of_pages = paginator.num_pages
page_num = min(page_num, number_of_pages)

# Create output page instance
try:
output_page = paginator.page(page_num, default_to_last_page)
except (EmptyPage, PageNotAnInteger):
if default_to_last_page:
page_num = paginator.num_pages
else:
page_num = 1
output_page = paginator.page(page_num, default_to_last_page)
output_page = paginator.page(page_num, default_to_last_page)

# Query string parameters
output_page.additional_parameters = query_string_parameters or { }
Expand Down

0 comments on commit 21d0114

Please sign in to comment.