1. Guillaume Camera
  2. WebHelpers


Guillaume Camera  committed 974a0c4

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

  • Participants
  • Parent commits 979fc45
  • Branches trunk

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)

File webhelpers/paginate.py

View file
  • Ignore whitespace
         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):