Fix bug with multiple paginations
authorAlbert Tugushev <albert@tugushev.ru>
Fri, 1 Jan 2016 07:43:58 +0000 (10:43 +0300)
committerAlbert Tugushev <albert@tugushev.ru>
Sat, 2 Jan 2016 16:31:33 +0000 (19:31 +0300)
Since `parser.tokens` doesn't returns a whole tokens of a template, in this
case the last remaining autopaginate tag makes `multiple_paginations` false,
so page-suffix of the last paginate tag will be empty.

linaro_django_pagination/templatetags/pagination_tags.py

index da22e95..d07bc61 100644 (file)
@@ -140,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 = ''