My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
PageLinks  
A utility class to produce a list of page links for navigation
Updated Jun 23, 2010 by bendavie...@gmail.com

About

PageLinks is a simple utility for producing a list of link URL and link text pairs. This is useful for the common convention of displaying a hyper-linked list of pages for page navigation.

picture of page navigation using PageLinks

PageLinks takes as input

  • the current page
  • total number of pages
  • the root of the URL used to generate links
  • the field used specify a page
  • the number of named pages to display apart from the current page (optional)

And returns a sequence of pairs (label, URL), including

  • A 'Prev' and 'Next' link for the page before and after the current page, but only where applicable (eg. No 'Prev' link on the first page, no 'Next' link on the last page, etc)
  • The current page
  • A number of page number labels before and after the current page, depending on the position of the current page.

Where

You can find the PagedLinks class in he3/db/tower/paging.py

Usage

To use the PageLinks class, simple instantiate it using its constructor, providing all of its required information in the process:

myLinks = PageLinks(page=10, page_count=20, url_root="/myresource", page_field="pg", page_range=3)

To get the list of links simple call the get_links() method.

page_navigation_links = myLinks.get_links()

In the above the case, the beginning of page_navigation_links looks something like this:

>>> page_navigation_links
>>> [('Prev','/myresource?pg=9'),('6','/myresource?pg=6'), ('7','/myresource?pg=7'), ...]
Comment by sylvain.vivien, Jun 23, 2010

page_field="pg"

So I think it should be (replace ?page=x with ?pg=x) >>> [('Prev','/myresource?pg=9'),('6','/myresource?pg=6'), ('7','/myresource?pg=7'), ...]

Comment by project member bendavie...@gmail.com, Jun 23, 2010

Good catch. Of course I put that there on purpose :)

Comment by ian.nott...@gmail.com, Aug 12, 2010

Hi there, The source files seems to be missing. You're linking to he3/db/tower/paging.py on this page (too).

Comment by project member bendavie...@gmail.com, Aug 14, 2010

Hi Ian, PageLinks is in the same module (paging.py) as PagedQuery. Scroll down :)


Sign in to add a comment
Powered by Google Project Hosting