Mike Verdone avatar Mike Verdone committed f22508c

Actually this implementation is nicer. Use link_previous_always as a key so you don't have to send an additional arg to pager.

Comments (0)

Files changed (2)

tests/test_paginate.py

 def test_show_previous_and_next_all_the_time():
     """
     Verify that symbol_previous and symbol_next appear as non-links
-    when show_previous_and_next_all_the_time is True.
+    when we use $link_previous_always and $link_next_always.
     """
     items = range(20)
     sym_prev = "previous_symbol"
     sym_next = "next_symbol"
     page = paginate.Page(items, page=0, items_per_page=5, url=url_generator)
     pager = page.pager(
-        format="$link_previous $link_next",
-        show_previous_and_next_all_the_time=True,
+        format="$link_previous_always $link_next_always",
         symbol_previous=sym_prev,
         symbol_next=sym_next)
     assert sym_prev in pager

webhelpers/paginate.py

         symbol_first='<<', symbol_last='>>',
         symbol_previous='<', symbol_next='>',
         link_attr={'class':'pager_link'}, curpage_attr={'class':'pager_curpage'},
-        dotdot_attr={'class':'pager_dotdot'},
-        show_previous_and_next_all_the_time=False, **kwargs):
+        dotdot_attr={'class':'pager_dotdot'}, **kwargs):
         """
         Return string with links to other pages (e.g. "1 2 [3] 4 5 6 7").
 
             - $link_last: link to last page (unless this is last page)
             - $link_previous: link to previous page (unless this is first page)
             - $link_next: link to next page (unless this is last page)
+            - $link_previous_always: link to previous page or non-linked symbol if on first page
+            - $link_next_always: link to next page or non-linked symbol if on last page
 
             To render a range of pages the token '~3~' can be used. The
             number sets the radius of pages around the current page.
 
             Default: False
 
-        show_previous_and_next_all_the_time:
-            if True the navigator previous and next symbols will show
-            even if there is no previous or next page. The symbols
-            will not be links in this case.
-
         link_attr (optional)
             A dictionary of attributes that get added to A-HREF links
             pointing to other pages. Can be used to define a CSS style
         self.onclick = onclick
         self.link_attr = link_attr
         self.dotdot_attr = dotdot_attr
-        self.show_previous_and_next_all_the_time = show_previous_and_next_all_the_time
 
         # Don't show navigator if there is no more than one page
         if self.page_count == 0 or (self.page_count == 1 and not show_if_single_page):
         # Replace ~...~ in token format by range of pages
         result = re.sub(r'~(\d+)~', self._range, format)
 
-        if self.previous_page:
-            link_previous = self._pagerlink(self.previous_page, symbol_previous)
-        elif self.show_previous_and_next_all_the_time:
-            link_previous = symbol_previous
-        else:
-            link_previous = ''
-
-        if self.next_page:
-            link_next = self._pagerlink(self.next_page, symbol_next)
-        elif self.show_previous_and_next_all_the_time:
-            link_next = symbol_next
-        else:
-            link_next = ''
-
         # Interpolate '%' variables
         result = Template(result).safe_substitute({
             'first_page': self.first_page,
                     self._pagerlink(self.first_page, symbol_first) or '',
             'link_last': self.page<self.last_page and \
                     self._pagerlink(self.last_page, symbol_last) or '',
-            'link_previous': link_previous,
-            'link_next': link_next,
+            'link_previous': self.previous_page and \
+                    self._pagerlink(self.previous_page, symbol_previous) or '',
+            'link_next': self.next_page and \
+                    self._pagerlink(self.next_page, symbol_next) or '',
+            'link_previous_always': self.previous_page and \
+                    self._pagerlink(self.previous_page, symbol_previous) \
+                    or symbol_previous,
+            'link_next_always': self.next_page and \
+                    self._pagerlink(self.next_page, symbol_next) \
+                    or symbol_next,
         })
 
         return literal(result)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.