From 9e4cbdbf078a716a6eb34c56ad2f65020a97d26a Mon Sep 17 00:00:00 2001 From: Gustavo Andres Morero Date: Tue, 17 May 2016 10:47:27 -0300 Subject: [PATCH] updates for django 1.9 support. --- pagination/middleware.py | 7 +++++-- pagination/templatetags/pagination_tags.py | 8 ++++---- pagination/tests.py | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pagination/middleware.py b/pagination/middleware.py index 676f909..045ba89 100644 --- a/pagination/middleware.py +++ b/pagination/middleware.py @@ -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 diff --git a/pagination/templatetags/pagination_tags.py b/pagination/templatetags/pagination_tags.py index 1d544f0..691deab 100644 --- a/pagination/templatetags/pagination_tags.py +++ b/pagination/templatetags/pagination_tags.py @@ -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. diff --git a/pagination/tests.py b/pagination/tests.py index f1cad49..0f94588 100644 --- a/pagination/tests.py +++ b/pagination/tests.py @@ -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)}) -- 2.45.2