Fix bug with multiple paginations
[django-pagination.git] / linaro_django_pagination / templatetags / pagination_tags.py
index a703928..d07bc61 100644 (file)
@@ -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 = ''
@@ -306,6 +315,7 @@ def paginate(context, window=DEFAULT_WINDOW, margin=DEFAULT_MARGIN):
         new_context = {
             'MEDIA_URL': settings.MEDIA_URL,
             'STATIC_URL': getattr(settings, "STATIC_URL", None),
+            'disable_link_for_first_page': DISABLE_LINK_FOR_FIRST_PAGE,
             'display_disabled_next_link': DISPLAY_DISABLED_NEXT_LINK,
             'display_disabled_previous_link': DISPLAY_DISABLED_PREVIOUS_LINK,
             'display_page_links': DISPLAY_PAGE_LINKS,
@@ -328,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()