Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable sorting by order number in template. Add django-sorting as a r…
…equirement
- Loading branch information
Showing
6 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
{% load display_tags %} | ||
|
||
<div> | ||
<ul class="pager"> | ||
{% if page_obj.has_previous %} | ||
<li class="previous"><a href="?page={{ page_obj.previous_page_number }}">previous</a></li> | ||
<li class="previous"><a href="?{% get_parameters page %}page={{ page_obj.previous_page_number }}">previous</a></li> | ||
{% endif %} | ||
<li class="current">Page {{ page_obj.number }} of {{ paginator.num_pages }}</li> | ||
{% if page_obj.has_next %} | ||
<li class="next"><a href="?page={{ page_obj.next_page_number }}">next</a></li> | ||
<li class="next"><a href="?{% get_parameters page %}page={{ page_obj.next_page_number }}">next</a></li> | ||
{% endif %} | ||
</ul> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from django import template | ||
|
||
register = template.Library() | ||
|
||
def get_parameters(parser, token): | ||
""" | ||
{% get_parameters except_field %} | ||
""" | ||
|
||
args = token.split_contents() | ||
if len(args) < 2: | ||
raise template.TemplateSyntaxError, "get_parameters tag takes at least 1 argument" | ||
return GetParametersNode(args[1].strip()) | ||
|
||
|
||
class GetParametersNode(template.Node): | ||
""" | ||
Renders current get parameters except for the specified parameter | ||
""" | ||
def __init__(self, field): | ||
self.field = field | ||
|
||
def render(self, context): | ||
request = context['request'] | ||
getvars = request.GET.copy() | ||
|
||
if self.field in getvars: | ||
del getvars[self.field] | ||
|
||
if len(getvars.keys()) > 0: | ||
get_params = "%s&" % getvars.urlencode() | ||
else: | ||
get_params = '' | ||
|
||
return get_params | ||
|
||
get_parameters = register.tag(get_parameters) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ twill==0.9 | |
PyHamcrest==1.6 | ||
South==0.7.3 | ||
purl==0.3.2 | ||
django-sorting==0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters