-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Per page #36
base: master
Are you sure you want to change the base?
Per page #36
Changes from all commits
809cfdf
8fc2692
1562c41
692cd84
4443339
55c3635
3204e3d
27084ee
8566afd
2446dee
4b32f1c
cbfa5b2
1148561
d71b9a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
django-pagination | ||
================= | ||
|
||
A set of utilities for creating robust pagination tools throughout a django application. | ||
|
||
This modification includes paginate_by tag for multi choice objects per page. | ||
|
||
Installation: | ||
================= | ||
In 'settings.py' add following lines (if they aren't already added): | ||
|
||
```python | ||
TEMPLATE_CONTEXT_PROCESSORS = ( | ||
"django.contrib.auth.context_processors.auth", | ||
"django.core.context_processors.media", | ||
"django.core.context_processors.request", | ||
"django.contrib.messages.context_processors.messages", | ||
"django.core.context_processors.static", | ||
) | ||
``` | ||
|
||
In the MIDDLEWARE_CLASSES add ```'pagination.middleware.PaginationMiddleware'``` | ||
|
||
And in the INSTALLED_APPS add ```'pagination'``` | ||
|
||
|
||
Example: | ||
================= | ||
```{% perpageselect 10 20 30 %}``` will show dropdown list with choices 10, 20 and 30 objects per page. | ||
```{% perpageanchors 10 20 30 %}``` will show anchors with choices 10, 20 and 30 objects per page. | ||
|
||
|
||
Usage: | ||
================= | ||
``` | ||
{% load pagination_tags %} | ||
|
||
{% autopaginate object_list 10 %} <!--OR THIS {% perpageselect 10 20 30 %} --> | ||
{% for post in object_list %} | ||
bla-bla-bla | ||
{% endfor %} | ||
{% paginate %} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# django-pagination Ukrainian translation. | ||
# Copyright (C) 2012, Maxym Lynnyk | ||
# This file is distributed under the WTFPL | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: PACKAGE VERSION\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2012-08-29 16:50+0200\n" | ||
"PO-Revision-Date: 2012-08-29 16:50+0200\n" | ||
"Last-Translator: Maxym Lynnyk \n" | ||
"Language-Team: TIPS \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 "попередня" | ||
|
||
#: templates/pagination/pagination.html:21 | ||
#: templates/pagination/pagination.html:23 | ||
msgid "next" | ||
msgstr "наступна" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{% load i18n %} | ||
<div class="perpageanchors"> | ||
{% for choice in choices %} | ||
<span> | ||
{% if perpage == choice %} | ||
{% if choice == 0 %}{% trans "All" %}{% else %}{{choice}}{% endif %} | ||
{% else %} | ||
<a href="?perpage={{choice}}">{% if choice == 0 %}{% trans "All" %}{% else %}{{choice}}{% endif %}</a> | ||
{% endif %} | ||
</span> | ||
{% endfor %} | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% load i18n %} | ||
<div class="perpageselect"> | ||
<form action="." method="GET" name="perpage" > | ||
<select name="perpage"> | ||
{% for choice in choices %} | ||
<option value="{{choice}}" {% if perpage = choice %} selected="selected" {% endif %}>{% if choice == 0 %}{% trans "All" %}{% else %}{{choice}}{% endif %}</option> | ||
{% endfor %} | ||
</select> | ||
<input type="submit" value="{% trans 'Select' %}" /> | ||
</form> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
from django import template | ||
from django.http import Http404 | ||
from django.core.paginator import Paginator, InvalidPage | ||
from django.core.paginator import Paginator, InvalidPage | ||
from django.conf import settings | ||
|
||
register = template.Library() | ||
|
@@ -51,7 +51,7 @@ def do_autopaginate(parser, token): | |
else: | ||
raise template.TemplateSyntaxError('%r tag takes one required ' + | ||
'argument and one optional argument' % split[0]) | ||
|
||
class AutoPaginateNode(template.Node): | ||
""" | ||
Emits the required objects to allow for Digg-style pagination. | ||
|
@@ -69,10 +69,10 @@ class AutoPaginateNode(template.Node): | |
tag. If you choose not to use *{% paginate %}*, make sure to display the | ||
list of available pages, or else the application may seem to be buggy. | ||
""" | ||
def __init__(self, queryset_var, paginate_by=DEFAULT_PAGINATION, | ||
def __init__(self, queryset_var, paginate_by=None, | ||
orphans=DEFAULT_ORPHANS, context_var=None): | ||
self.queryset_var = template.Variable(queryset_var) | ||
if isinstance(paginate_by, int): | ||
if (paginate_by == None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be:
|
||
self.paginate_by = paginate_by | ||
else: | ||
self.paginate_by = template.Variable(paginate_by) | ||
|
@@ -82,10 +82,13 @@ 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): | ||
paginate_by = self.paginate_by | ||
if (self.paginate_by == None): | ||
paginate_by = int(context['request'].perpage) | ||
else: | ||
paginate_by = self.paginate_by.resolve(context) | ||
if (paginate_by == 0): | ||
context['page_obj'] = value | ||
return u'' | ||
paginator = Paginator(value, paginate_by, self.orphans) | ||
try: | ||
page_obj = paginator.page(context['request'].page) | ||
|
@@ -99,7 +102,7 @@ def render(self, context): | |
if self.context_var is not None: | ||
context[self.context_var] = page_obj.object_list | ||
else: | ||
context[key] = page_obj.object_list | ||
context[key] = page_obj.object_list | ||
context['paginator'] = paginator | ||
context['page_obj'] = page_obj | ||
return u'' | ||
|
@@ -222,9 +225,35 @@ def paginate(context, window=DEFAULT_WINDOW, hashtag=''): | |
else: | ||
to_return['getvars'] = '' | ||
return to_return | ||
except KeyError, AttributeError: | ||
except (KeyError, AttributeError): | ||
return {} | ||
|
||
register.inclusion_tag('pagination/pagination.html', takes_context=True)( | ||
paginate) | ||
register.tag('autopaginate', do_autopaginate) | ||
|
||
|
||
@register.inclusion_tag('pagination/perpageselect.html', takes_context='True') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be:
|
||
def perpageselect (context, *args): | ||
""" | ||
Reads the arguments to the perpageselect tag and formats them correctly. | ||
""" | ||
try: | ||
choices = [int(x) for x in args] | ||
perpage = int(context['request'].perpage) | ||
return {'choices': choices, 'perpage': perpage} | ||
except(TypeError, ValueError): | ||
raise template.TemplateSyntaxError(u'Got %s, but expected integer.' % args) | ||
|
||
|
||
@register.inclusion_tag('pagination/perpageanchors.html', takes_context='True') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be:
|
||
def perpageanchors (context, *args): | ||
""" | ||
Reads the arguments to the perpageanchors tag and formats them correctly. | ||
""" | ||
try: | ||
choices = [int(x) for x in args] | ||
perpage = int(context['request'].perpage) | ||
return {'choices': choices, 'perpage': perpage} | ||
except(TypeError, ValueError): | ||
raise template.TemplateSyntaxError(u'Got %s, but expected integer.' % args) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove all whitespace