Implements zyga/django-pagination#22
[django-pagination.git] / linaro_django_pagination / templatetags / pagination_tags.py
index 1577452..995edc3 100644 (file)
@@ -60,7 +60,7 @@ def do_autopaginate(parser, token):
     # Check whether there are any other autopaginations are later in this template
     expr = lambda obj: (obj.token_type == TOKEN_BLOCK and \
         len(obj.split_contents()) > 0 and obj.split_contents()[0] == "autopaginate")
-    multiple_paginations = len(filter(expr, parser.tokens)) > 0
+    multiple_paginations = len([tok for tok in parser.tokens if expr(tok)]) > 0
 
     i = iter(token.split_contents())
     paginate_by = None
@@ -69,26 +69,26 @@ def do_autopaginate(parser, token):
     orphans = None
     word = None
     try:
-        word = i.next()
+        word = next(i)
         assert word == "autopaginate"
-        queryset_var = i.next()
-        word = i.next()
+        queryset_var = next(i)
+        word = next(i)
         if word != "as":
             paginate_by = word
             try:
                 paginate_by = int(paginate_by)
             except ValueError:
                 pass
-            word = i.next()
+            word = next(i)
         if word != "as":
             orphans = word
             try:
                 orphans = int(orphans)
             except ValueError:
                 pass
-            word = i.next()
+            word = next(i)
         assert word == "as"
-        context_var = i.next()
+        context_var = next(i)
     except StopIteration:
         pass
     if queryset_var is None:
@@ -306,6 +306,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,
@@ -326,12 +327,12 @@ def paginate(context, window=DEFAULT_WINDOW, margin=DEFAULT_MARGIN):
                 new_context['getvars'] = "&%s" % getvars.urlencode()
             else:
                 new_context['getvars'] = ''
-
-        context.update(new_context)
-
+        return new_context
     except (KeyError, AttributeError):
         pass
 
+    return context
+
 
 register = Library()
 register.tag('paginate', do_paginate)