M => +5 -2
@@ 4,7 4,10 @@ def get_page(self, suffix):
integer representing the current page.
"""
try:
return int(self.REQUEST['page%s' % suffix])
if self.method == "POST":
return int(self.POST['page%s' % suffix])
else:
return int(self.GET['page%s' % suffix])
except (KeyError, ValueError, TypeError):
return 1
@@ 14,4 17,4 @@ class PaginationMiddleware(object):
it exists in either **GET** or **POST** portions of the request.
"""
def process_request(self, request):
request.__class__.page = get_page
\ No newline at end of file
request.__class__.page = get_page
M => +4 -4
@@ 4,7 4,7 @@ except NameError:
from sets import Set as set
from django import template
from django.template import TOKEN_BLOCK
from django.template.base import TOKEN_BLOCK
from django.http import Http404
from django.core.paginator import Paginator, InvalidPage
from django.conf import settings
@@ 156,8 156,8 @@ def paginate(context, window=DEFAULT_WINDOW, hashtag=''):
records['last'] = paginator.count
# First and last are simply the first *n* pages and the last *n* pages,
# where *n* is the current window size.
first = set(page_range[:window])
last = set(page_range[-window:])
first = set(tuple(page_range)[:window])
last = set(tuple(page_range)[-window:])
# Now we look around our current page, making sure that we don't wrap
# around.
current_start = page_obj.number-1-window
@@ 166,7 166,7 @@ def paginate(context, window=DEFAULT_WINDOW, hashtag=''):
current_end = page_obj.number-1+window
if current_end < 0:
current_end = 0
current = set(page_range[current_start:current_end])
current = set(tuple(page_range)[current_start:current_end])
pages = []
# If there's no overlap between the first set of pages and the current
# set of pages, then there's a possible need for elusion.
M => +1 -1
@@ 1,7 1,7 @@
"""
>>> from django.core.paginator import Paginator
>>> from pagination.templatetags.pagination_tags import paginate
>>> from django.template import Template, Context
>>> from django.template.base import Template, Context
>>> p = Paginator(range(15), 2)
>>> pg = paginate({'paginator': p, 'page_obj': p.page(1)})