From: Fabio Corneti Date: Thu, 22 Apr 2010 10:01:19 +0000 (+0200) Subject: Custom pagination templates X-Git-Tag: release-2.0~32^2^2~4 X-Git-Url: https://git.mdrn.pl/django-pagination.git/commitdiff_plain/4d2a206de588ee12f898d35bd81e6f76bda9bc94 Custom pagination templates --- diff --git a/docs/usage.txt b/docs/usage.txt index b520169..31dad6d 100644 --- a/docs/usage.txt +++ b/docs/usage.txt @@ -69,6 +69,19 @@ 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. +Custom pagination templates +--------------------------- + +In order to override the default pagination template, declare a context variable +named ``pagination_template`` set to the template name:: + + {% with 'pagination/blog/post.html' as pagination_template %} + {% autopaginate posts pagesize %} + {% paginate %} + {% endwith %} + +The default pagination template is contained in the ``pagination/default.html`` +file inside the distribution. A Note About Uploads -------------------- @@ -103,4 +116,21 @@ pagination tags. Here's an overview: ``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 + does the latter. + +``DISPLAY_PAGE_LINKS`` + If set to ``False``, links for single pages will not be displayed. + +``PREVIOUS_LINK_DECORATOR`` + An HTML prefix for the previous page link; the default value is ``‹‹ ``. + +``NEXT_LINK_DECORATOR`` + An HTML postfix for the next page link; the default value is `` ››``. + +``DISPLAY_DISABLED_PREVIOUS_LINK`` + If set to ``False``, the previous page link will not be displayed if there's + no previous page. + +``DISPLAY_DISABLED_NEXT_LINK`` + If set to ``False``, the next page link will not be displayed if there's no + next page. diff --git a/pagination/templates/pagination/default.html b/pagination/templates/pagination/default.html new file mode 100644 index 0000000..794765b --- /dev/null +++ b/pagination/templates/pagination/default.html @@ -0,0 +1,38 @@ +{% if is_paginated %} + {% load i18n %} + +{% endif %} \ No newline at end of file diff --git a/pagination/templates/pagination/pagination.html b/pagination/templates/pagination/pagination.html index 8dd3679..fd925f0 100644 --- a/pagination/templates/pagination/pagination.html +++ b/pagination/templates/pagination/pagination.html @@ -1,32 +1 @@ -{% if is_paginated %} -{% load i18n %} - -{% endif %} \ No newline at end of file +{% include pagination_template %} diff --git a/pagination/templatetags/pagination_tags.py b/pagination/templatetags/pagination_tags.py old mode 100644 new mode 100755 index f7de347..fe4bd07 --- a/pagination/templatetags/pagination_tags.py +++ b/pagination/templatetags/pagination_tags.py @@ -134,11 +134,17 @@ def paginate(context, window=DEFAULT_WINDOW, hashtag=''): A dictionary of all of the **GET** parameters in the current request. This is useful to maintain certain types of state, even when requesting a different page. - """ + + ``pagination_template`` + A custom template to include in place of the default ``pagination.html`` + contents. + + """ try: paginator = context['paginator'] page_obj = context['page_obj'] page_range = paginator.page_range + pagination_template = context.get('pagination_template', 'pagination/default.html') # Calculate the record range in the current page for display. records = {'first': 1 + (page_obj.number - 1) * paginator.per_page} records['last'] = records['first'] + paginator.per_page - 1 @@ -222,6 +228,7 @@ def paginate(context, window=DEFAULT_WINDOW, hashtag=''): 'display_disabled_next_link': DISPLAY_DISABLED_NEXT_LINK, 'previous_link_decorator': PREVIOUS_LINK_DECORATOR, 'next_link_decorator': NEXT_LINK_DECORATOR, + 'pagination_template': pagination_template, } if 'request' in context: getvars = context['request'].GET.copy()