Commits

Guillaume Camera committed 974a0c4

Can provide a HTML wrapper for links created by Page.pager

Comments (1)

  1. Guillaume Camera author

    Sorry the bad English.

    The correct docstring could be :

    "Allow to add HTML tag over A-HREF for the final render."

    It was late when the commit was done, I was not so concentrated about English :)

    If the idea is accepted, the next commit can allow the pager to provide an other attribut like link_wrapper_attr and apply it on the HTML tag.

Files changed (1)

webhelpers/paginate.py

         show_if_single_page=False, separator=' ', onclick=None,
         symbol_first='<<', symbol_last='>>',
         symbol_previous='<', symbol_next='>',
-        link_attr={'class':'pager_link'}, curpage_attr={'class':'pager_curpage'},
+        link_attr={'class':'pager_link'}, link_wrapper=None,
+        curpage_attr={'class':'pager_curpage'},
         dotdot_attr={'class':'pager_dotdot'}, **kwargs):
         """
         Return string with links to other pages (e.g. "1 2 [3] 4 5 6 7").
 
             Default: { 'class':'pager_link' }
 
+        link_wrapper (optional)
+            A string as HTML tag to wrap the A-HREF generated for link.
+            Can permitte to add HTML tag aver A-HREF for the final render.
+
+            Example: 'li'
+
+            Default: None
+
         curpage_attr (optional)
             A dictionary of attributes that get added to the current 
             page number in the pager (which is obviously not a link).
         self.partial_param = partial_param
         self.onclick = onclick
         self.link_attr = link_attr
+        self.link_wrapper = link_wrapper
         self.dotdot_attr = dotdot_attr
 
         # Don't show navigator if there is no more than one page
         if self.page != self.last_page and rightmost_page < self.last_page:
             nav_items.append( self._pagerlink(self.last_page, self.last_page) )
 
+        # Wrap the link created over an HTML tag, if asked.
+        if self.link_wrapper:
+            wrapper = getattr(HTML, self.link_wrapper)
+            nav_items = [ wrapper(nav_item) for nav_item in nav_items ]
+
         return self.separator.join(nav_items)
 
     def _pagerlink(self, page, text):
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.