From 32e1b9e7747ded444ca6e9fc1d578f74dde6acae Mon Sep 17 00:00:00 2001 From: resteve Date: Wed, 23 Nov 2011 14:10:47 +0100 Subject: [PATCH 1/4] [ADD] README --- README | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000..54d3066 --- /dev/null +++ b/README @@ -0,0 +1,106 @@ +How to use django-pagination +---------------------------- + +``django-pagination`` allows for easy Digg-style pagination without modifying +your views. + +There are really 5 steps to setting it up with your projects (not including +installation, which is covered in INSTALL.txt in this same directory.) + +1. List this application in the ``INSTALLED_APPS`` portion of your settings + file. Your settings file might look something like:: + + INSTALLED_APPS = ( + # ... + 'pagination', + ) + + +2. Install the pagination middleware. Your settings file might look something + like:: + + MIDDLEWARE_CLASSES = ( + # ... + 'pagination.middleware.PaginationMiddleware', + ) + +3. If it's not already added in your setup, add the request context processor. + Note that context processors are set by default implicitly, so to set them + explicitly, you need to copy and paste this code into your under + the value TEMPLATE_CONTEXT_PROCESSORS:: + + ("django.core.context_processors.auth", + "django.core.context_processors.debug", + "django.core.context_processors.i18n", + "django.core.context_processors.media", + "django.core.context_processors.request") + +4. Add this line at the top of your template to load the pagination tags: + + {% load pagination_tags %} + + +5. Decide on a variable that you would like to paginate, and use the + autopaginate tag on that variable before iterating over it. This could + take one of two forms (using the canonical ``object_list`` as an example + variable): + + {% autopaginate object_list %} + + This assumes that you would like to have the default 20 results per page. + If you would like to specify your own amount of results per page, you can + specify that like so: + + {% autopaginate object_list 10 %} + + Note that this replaces ``object_list`` with the list for the current page, so + you can iterate over the ``object_list`` like you normally would. + + +6. Now you want to display the current page and the available pages, so + somewhere after having used autopaginate, use the paginate inclusion tag: + + {% paginate %} + + This does not take any arguments, but does assume that you have already + called autopaginate, so make sure to do so first. + + +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. + + +A Note About Uploads +-------------------- + +It is important, when using django-pagination in conjunction with file uploads, +to be aware of when ``request.page`` is accessed. As soon as ``request.page`` +is accessed, ``request.upload_handlers`` is frozen and cannot be altered in any +way. It's a good idea to access the ``page`` attribute on the request object +as late as possible in 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. From b850d756f403dd64bb5dc77646ec040874aafd91 Mon Sep 17 00:00:00 2001 From: Enric Caumons Date: Wed, 23 Nov 2011 20:33:04 +0100 Subject: [PATCH 2/4] [IMP] Add DEFAULT_PAGINATION in context (if specified as context[paginator_option]) or default paginator in settings as PAGINATOR_TOTAL --- pagination/templatetags/pagination_tags.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) mode change 100644 => 100755 pagination/templatetags/pagination_tags.py diff --git a/pagination/templatetags/pagination_tags.py b/pagination/templatetags/pagination_tags.py old mode 100644 new mode 100755 index ae843b1..90d5497 --- a/pagination/templatetags/pagination_tags.py +++ b/pagination/templatetags/pagination_tags.py @@ -10,7 +10,7 @@ register = template.Library() -DEFAULT_PAGINATION = getattr(settings, 'PAGINATION_DEFAULT_PAGINATION', 20) +DEFAULT_PAGINATION = getattr(settings, 'PAGINATOR_TOTAL', 9) # aka PAGINATION_DEFAULT_PAGINATION DEFAULT_WINDOW = getattr(settings, 'PAGINATION_DEFAULT_WINDOW', 4) DEFAULT_ORPHANS = getattr(settings, 'PAGINATION_DEFAULT_ORPHANS', 0) INVALID_PAGE_RAISES_404 = getattr(settings, @@ -82,7 +82,9 @@ def __init__(self, queryset_var, paginate_by=DEFAULT_PAGINATION, def render(self, context): key = self.queryset_var.var value = self.queryset_var.resolve(context) - if isinstance(self.paginate_by, int): + if "paginator_option" in context: # User has defined how many items wants to see per page + paginate_by = context["paginator_option"] + elif isinstance(self.paginate_by, int): paginate_by = self.paginate_by else: paginate_by = self.paginate_by.resolve(context) From 1734859c2488f077c60c64b281252cd9da567a7f Mon Sep 17 00:00:00 2001 From: resteve Date: Thu, 22 Dec 2011 12:20:53 +0100 Subject: [PATCH 3/4] [IMP] Locale ca and es --- pagination/locale/ca/LC_MESSAGES/django.mo | Bin 0 -> 453 bytes pagination/locale/ca/LC_MESSAGES/django.po | 27 +++++++++++++++++++++ pagination/locale/es/LC_MESSAGES/django.mo | Bin 0 -> 454 bytes pagination/locale/es/LC_MESSAGES/django.po | 27 +++++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 pagination/locale/ca/LC_MESSAGES/django.mo create mode 100644 pagination/locale/ca/LC_MESSAGES/django.po create mode 100644 pagination/locale/es/LC_MESSAGES/django.mo create mode 100644 pagination/locale/es/LC_MESSAGES/django.po diff --git a/pagination/locale/ca/LC_MESSAGES/django.mo b/pagination/locale/ca/LC_MESSAGES/django.mo new file mode 100644 index 0000000000000000000000000000000000000000..dbd81132fb97e61191f36a516d4d004e736a78aa GIT binary patch literal 453 zcmYL_-%i3X6vn4wVs`1Z7ri&dbt=J$1e}u)$DfSBwRJnp3Tv0H5am655^uTlJ$x3= z(CA5j?P>G%>pA^8uDx3r2gnI>fgBWhPR3yUI!$ zE05UYQA~Xe+~6g8#|?PIb(|~eoKw~ytl_zhQ-?VY3TcGTRpx&>#wc^C>k`I1_wq*< z^3u>)b6GCAQQ9LB7rBxoC=INEv^4CJ&PFUYe33&ccs)^h+YY(RRy+e51J6AYc89%b z)j%r@J4;blI&0g5{vh~ok<}gBSJHsQ7vBmj-Qc&J6-zGUHA$YiF2USP<9pit*Hx9x eLDN7cDit#GNb^Y;+nPZ3xkV?di-uY#ZG8h$A$WWM literal 0 HcmV?d00001 diff --git a/pagination/locale/ca/LC_MESSAGES/django.po b/pagination/locale/ca/LC_MESSAGES/django.po new file mode 100644 index 0000000..e14316d --- /dev/null +++ b/pagination/locale/ca/LC_MESSAGES/django.po @@ -0,0 +1,27 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2009-03-16 16:26+0100\n" +"PO-Revision-Date: 2011-12-22 11:25+0100\n" +"Last-Translator: Raimon Esteve \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: templates/pagination/pagination.html:5 +#: templates/pagination/pagination.html:7 +msgid "previous" +msgstr "Anterior" + +#: templates/pagination/pagination.html:21 +#: templates/pagination/pagination.html:23 +msgid "next" +msgstr "Següent" + diff --git a/pagination/locale/es/LC_MESSAGES/django.mo b/pagination/locale/es/LC_MESSAGES/django.mo new file mode 100644 index 0000000000000000000000000000000000000000..2cc51ee17ad38cfbe397ff75e7ce6bb8a39d0cc2 GIT binary patch literal 454 zcmYL_%}&BV5XY-xqCI-{uy?cAt%hJlLamh$%STG#?Ai`>1$LY5mMHJxlX&)3d={r1 zV6wlN$>zWFv40nhZwu`NxkPS}QzSxadqo-uN6wH15*%5U!g!ASU|!$!p{zw%%X3>-4s#q7(iq#-#rHbKD08Xn62|trh?j;Y zn#*#8xmYVn!qUJ7NJqmi>21Yw%a?1&1aGEl-L)ew^NQy{6X0u)ME#``?@9X3bqVHSmORt;L03<<08K-g as!Yh-Bkea~Y-=j=N?;|hd~{kUZT$nr6?jJg literal 0 HcmV?d00001 diff --git a/pagination/locale/es/LC_MESSAGES/django.po b/pagination/locale/es/LC_MESSAGES/django.po new file mode 100644 index 0000000..7e176ba --- /dev/null +++ b/pagination/locale/es/LC_MESSAGES/django.po @@ -0,0 +1,27 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2009-03-16 16:26+0100\n" +"PO-Revision-Date: 2011-12-22 11:26+0100\n" +"Last-Translator: Raimon Esteve \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: templates/pagination/pagination.html:5 +#: templates/pagination/pagination.html:7 +msgid "previous" +msgstr "Anterior" + +#: templates/pagination/pagination.html:21 +#: templates/pagination/pagination.html:23 +msgid "next" +msgstr "Siguiente" + From 2deb86b5ec8011b642a5420b3b195b303bea985d Mon Sep 17 00:00:00 2001 From: resteve Date: Thu, 22 Dec 2011 12:36:15 +0100 Subject: [PATCH 4/4] [IMP] Change PAGINATION_DEFAULT_PAGINATION to PAGINATION_DEFAULT_TOTAL value --- README | 2 +- pagination/templatetags/pagination_tags.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README b/README index 54d3066..6d0260e 100644 --- a/README +++ b/README @@ -87,7 +87,7 @@ 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`` +``PAGINATION_DEFAULT_TOTAL`` The default amount of items to show on a page if no number is specified. ``PAGINATION_DEFAULT_WINDOW`` diff --git a/pagination/templatetags/pagination_tags.py b/pagination/templatetags/pagination_tags.py index 90d5497..7dbdb84 100755 --- a/pagination/templatetags/pagination_tags.py +++ b/pagination/templatetags/pagination_tags.py @@ -10,7 +10,7 @@ register = template.Library() -DEFAULT_PAGINATION = getattr(settings, 'PAGINATOR_TOTAL', 9) # aka PAGINATION_DEFAULT_PAGINATION +DEFAULT_PAGINATION = getattr(settings, 'PAGINATION_DEFAULT_TOTAL', 9) # aka PAGINATION_DEFAULT_PAGINATION DEFAULT_WINDOW = getattr(settings, 'PAGINATION_DEFAULT_WINDOW', 4) DEFAULT_ORPHANS = getattr(settings, 'PAGINATION_DEFAULT_ORPHANS', 0) INVALID_PAGE_RAISES_404 = getattr(settings,