X-Git-Url: https://git.mdrn.pl/django-pagination.git/blobdiff_plain/4b2ba62948c5104fc3cae8d24face3c4bf7378df..b180263fd69054c1f16a3c97b283026137c78d7c:/linaro_django_pagination/templatetags/pagination_tags.py diff --git a/linaro_django_pagination/templatetags/pagination_tags.py b/linaro_django_pagination/templatetags/pagination_tags.py index 995edc3..d6e121e 100644 --- a/linaro_django_pagination/templatetags/pagination_tags.py +++ b/linaro_django_pagination/templatetags/pagination_tags.py @@ -37,11 +37,16 @@ from django.template import ( Context, Library, Node, - TOKEN_BLOCK, TemplateSyntaxError, Variable, loader, ) + +try: + from django.template.base import TOKEN_BLOCK +except ImportError: # Django < 1.8 + from django.template import TOKEN_BLOCK + from django.template.loader import select_template from django.utils.text import unescape_string_literal @@ -135,7 +140,11 @@ class AutoPaginateNode(Node): self.multiple_paginations = multiple_paginations def render(self, context): - if self.multiple_paginations or getattr(context, "paginator", None): + # Save multiple_paginations state in context + if self.multiple_paginations and 'multiple_paginations' not in context: + context['multiple_paginations'] = True + + if context.get('multiple_paginations') or getattr(context, "paginator", None): page_suffix = '_%s' % self.queryset_var else: page_suffix = '' @@ -259,7 +268,7 @@ def paginate(context, window=DEFAULT_WINDOW, margin=DEFAULT_MARGIN): paginator = context['paginator'] page_obj = context['page_obj'] page_suffix = context.get('page_suffix', '') - page_range = paginator.page_range + page_range = list(paginator.page_range) # Calculate the record range in the current page for display. records = {'first': 1 + (page_obj.number - 1) * paginator.per_page} records['last'] = records['first'] + paginator.per_page - 1 @@ -329,9 +338,7 @@ def paginate(context, window=DEFAULT_WINDOW, margin=DEFAULT_MARGIN): new_context['getvars'] = '' return new_context except (KeyError, AttributeError): - pass - - return context + return {} register = Library()