Pagination shortcut

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
def paginate(request, objects, count=10, param_name='page'):
    """
    Shortcut for paginating by some object
    """
    paginator = Paginator(objects, count)

    try:
        pagenum = int(request.GET.get('%s' % param_name, '1'))
    except ValueError:
        pagenum = 1
    
    try:
        result = paginator.page(pagenum)
    except (EmptyPage, InvalidPage):
        result = paginator.page(paginator.num_pages)
    
    return result

More like this

  1. Format transition middleware by limodou 4 years, 11 months ago
  2. Extend generic view object_list to support paginate_by via cookies by kersurk 1 year ago
  3. Basic CouchDB Paginator (Updated) by toke 3 years, 2 months ago
  4. object-oriented generic views by carljm 3 years, 5 months ago
  5. Lazily lookup dynamically for templates by axiak 3 years, 11 months ago

Comments

(Forgotten your password?)