From: floguy Date: Thu, 4 Dec 2008 09:49:27 +0000 (+0000) Subject: Fixed #28. Added the ability for the autopaginate tag to raise an Http404. Also... X-Git-Tag: 1.0.6~12 X-Git-Url: https://git.mdrn.pl/django-pagination.git/commitdiff_plain/1df6507872d73ee387eb375428eafbfc253dfcd8?ds=sidebyside Fixed #28. Added the ability for the autopaginate tag to raise an Http404. Also documented that feature as well as the other settings. git-svn-id: https://django-pagination.googlecode.com/svn/trunk@45 7f1efe38-554e-0410-b69d-834cb44da2d5 --- diff --git a/docs/install.txt b/docs/install.txt index b370b5d..d178755 100644 --- a/docs/install.txt +++ b/docs/install.txt @@ -1,5 +1,5 @@ -Installing django-pagination ----------------------------- +Installing the latest development version of django-pagination +--------------------------------------------------------------- To install, first check out the latest version of the application from subversion: @@ -15,5 +15,26 @@ do the trick for you: sudo ln -s `pwd`/pagination `python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"`/pagination -Now it's installed. Please see README.txt for information on how to use this -application in your projects. \ No newline at end of file +Now it's installed! Please see usage.txt for information on how to use this +application in your projects. + +Installing via setup.py +----------------------- + +Included with this application is a file named ``setup.py``. It's possible to +use this file to install this application to your system, by invoking the +following command: + + sudo python setup.py install + +Once that's done, you should be able to begin using django-pagination at will. + +Installing via setuptools +------------------------- + +If you have setuptools_ installed, you can simply run the following command +to install django-pagination: + + sudo easy_install django-pagination + +.. _setuptools: http://peak.telecommunity.com/DevCenter/setuptools \ No newline at end of file diff --git a/docs/usage.txt b/docs/usage.txt index 1a86b09..9c97c51 100644 --- a/docs/usage.txt +++ b/docs/usage.txt @@ -68,3 +68,29 @@ installation, which is covered in INSTALL.txt in this same directory.) That's it! You have now paginated ``object_list`` and given users of the site a way to navigate between the different pages--all without touching your views. + + +Optional Settings +------------------ + +In django-pagination, there are no required settings. There are, however, a +small set of optional settings useful for changing the default behavior of the +pagination tags. Here's an overview: + +``PAGINATION_DEFAULT_PAGINATION`` + The default amount of items to show on a page if no number is specified. + +``PAGINATION_DEFAULT_WINDOW`` + The number of items to the left and to the right of the current page to + display (accounting for ellipses). + +``PAGINATION_DEFAULT_ORPHANS`` + The number of orphans allowed. According to the Django documentation, + orphans are defined as:: + + The minimum number of items allowed on the last page, defaults to zero. + +``PAGINATION_INVALID_PAGE_RAISES_404`` + Determines whether an invalid page raises an ``Http404`` or just sets the + ``invalid_page`` context variable. ``True`` does the former and ``False`` + does the latter. \ No newline at end of file diff --git a/pagination/templatetags/pagination_tags.py b/pagination/templatetags/pagination_tags.py index 3442fcd..7505b74 100644 --- a/pagination/templatetags/pagination_tags.py +++ b/pagination/templatetags/pagination_tags.py @@ -2,7 +2,9 @@ try: set except NameError: from sets import Set as set + from django import template +from django.http import Http404 from django.core.paginator import Paginator, InvalidPage from django.conf import settings @@ -11,6 +13,8 @@ register = template.Library() DEFAULT_PAGINATION = getattr(settings, 'PAGINATION_DEFAULT_PAGINATION', 20) DEFAULT_WINDOW = getattr(settings, 'PAGINATION_DEFAULT_WINDOW', 4) DEFAULT_ORPHANS = getattr(settings, 'PAGINATION_DEFAULT_ORPHANS', 0) +INVALID_PAGE_RAISES_404 = getattr(settings, 'PAGINATION_INVALID_PAGE_RAISES_404', + False) def do_autopaginate(parser, token): """ @@ -85,6 +89,9 @@ class AutoPaginateNode(template.Node): try: page_obj = paginator.page(context['request'].page) except InvalidPage: + if INVALID_PAGE_RAISES_404: + raise Http404('Invalid page requested. If DEBUG were set to ' + + 'False, an HTTP 404 page would have been shown instead.') context[key] = [] context['invalid_page'] = True return u'' diff --git a/setup.py b/setup.py index ea32ae2..646f84e 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -version = '1.0.4' +version = '1.0.5' LONG_DESCRIPTION = """ How to use django-pagination @@ -73,6 +73,32 @@ installation, which is covered in INSTALL.txt in this same directory.) That's it! You have now paginated ``object_list`` and given users of the site a way to navigate between the different pages--all without touching your views. + + +Optional Settings +------------------ + +In django-pagination, there are no required settings. There are, however, a +small set of optional settings useful for changing the default behavior of the +pagination tags. Here's an overview: + +``PAGINATION_DEFAULT_PAGINATION`` + The default amount of items to show on a page if no number is specified. + +``PAGINATION_DEFAULT_WINDOW`` + The number of items to the left and to the right of the current page to + display (accounting for ellipses). + +``PAGINATION_DEFAULT_ORPHANS`` + The number of orphans allowed. According to the Django documentation, + orphans are defined as:: + + The minimum number of items allowed on the last page, defaults to zero. + +``PAGINATION_INVALID_PAGE_RAISES_404`` + Determines whether an invalid page raises an ``Http404`` or just sets the + ``invalid_page`` context variable. ``True`` does the former and ``False`` + does the latter. """ setup(