-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed pagination of project listing page (& cleaned up & refactored)
* cleaned up project list view * refactored / cleaned up domain function to list / filter public projects and began domain namespace for projects * fixed pagination of project listing page -- no longer discards filters as discusssed in #54, the platform's listing pages all suffer from submitting filters via POST, and previously from a pagination template which discarded any GET query params besides its own page number. the first problem was resolved in previous clean-up of the project listing view. this change fixes the pagination template, globally. the net result is that only the pagination of the project listing page is fixed, for now. (but the other pages may now be fixed by switching to GETs, alone.)
- Loading branch information
Showing
8 changed files
with
209 additions
and
112 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
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
22 changes: 12 additions & 10 deletions
22
src/marketplace/templates/marketplace/components/pagination.html
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,39 +1,41 @@ | ||
{% if page_obj.has_other_pages %} | ||
{% load params %} | ||
|
||
<nav aria-label="Page navigation example"> | ||
{% if page_obj.has_other_pages %} | ||
{% with pagename=pagename|default:'page' %} | ||
<nav aria-label="Page navigation"> | ||
<ul class="pagination justify-content-center"> | ||
{% if page_obj.has_previous %} | ||
<li class="page-item"><a class="page-link" href="{{ baseurl }}?{{ pagename|default:'page' }}=1"><i class="fa fa-angle-double-left" aria-hidden="true"></i></a></li> | ||
<li class="page-item"><a class="page-link" href="{{ baseurl }}?{{ pagename|default:'page' }}={{ page_obj.previous_page_number }}"><i class="fa fa-angle-left" aria-hidden="true"></i></a></li> | ||
<li class="page-item"><a class="page-link" href="{% set_params_path pagename 1 %}"><i class="fa fa-angle-double-left" aria-hidden="true"></i></a></li> | ||
<li class="page-item"><a class="page-link" href="{% set_params_path pagename page_obj.previous_page_number %}"><i class="fa fa-angle-left" aria-hidden="true"></i></a></li> | ||
{% else %} | ||
<li class="page-item disabled"><a class="page-link disabled" href="#"><i class="fa fa-angle-double-left" aria-hidden="true"></i></a></li> | ||
<li class="page-item disabled"><a class="page-link disabled" href="#"><i class="fa fa-angle-left" aria-hidden="true"></i></a></li> | ||
{% endif %} | ||
|
||
{% if page_obj.number|add:'-4' > 1 %} | ||
<li class="page-item"><a class="page-link" href="{{ baseurl }}?{{ pagename|default:'page' }}={{ page_obj.number|add:'-5' }}">…</a></li> | ||
|
||
<li class="page-item"><a class="page-link" href="{% set_params_path pagename page_obj.number|add:'-5' %}">…</a></li> | ||
{% endif %} | ||
|
||
{% for i in page_obj.paginator.page_range %} | ||
{% if page_obj.number == i %} | ||
<li class="page-item active"><span class="page-link">{{ i }} <span class="sr-only">(current)</span></span></li> | ||
{% elif i > page_obj.number|add:'-5' and i < page_obj.number|add:'5' %} | ||
<li class="page-item"><a class="page-link" href="{{ baseurl }}?{{ pagename|default:'page' }}={{ i }}">{{ i }}</a></li> | ||
<li class="page-item"><a class="page-link" href="{% set_params_path pagename i %}">{{ i }}</a></li> | ||
{% endif %} | ||
{% endfor %} | ||
|
||
{% if page_obj.paginator.num_pages > page_obj.number|add:'4' %} | ||
<li class="page-item"><a class="page-link" href="{{ baseurl }}?{{ pagename|default:'page' }}={{ page_obj.number|add:'5' }}">…</a></li> | ||
<li class="page-item"><a class="page-link" href="{% set_params_path pagename page_obj.number|add:'5' %}">…</a></li> | ||
{% endif %} | ||
|
||
{% if page_obj.has_next %} | ||
<li class="page-item"><a class="page-link" href="{{ baseurl }}?{{ pagename|default:'page' }}={{ page_obj.next_page_number }}"><i class="fa fa-angle-right" aria-hidden="true"></i></a></li> | ||
<li class="page-item"><a class="page-link" href="{{ baseurl }}?{{ pagename|default:'page' }}={{ page_obj.paginator.num_pages }}"><i class="fa fa-angle-double-right" aria-hidden="true"></i></a></li> | ||
<li class="page-item"><a class="page-link" href="{% set_params_path pagename page_obj.next_page_number %}"><i class="fa fa-angle-right" aria-hidden="true"></i></a></li> | ||
<li class="page-item"><a class="page-link" href="{% set_params_path pagename page_obj.paginator.num_pages %}"><i class="fa fa-angle-double-right" aria-hidden="true"></i></a></li> | ||
{% else %} | ||
<li class="page-item disabled"><a class="page-link disabled" href="#"><i class="fa fa-angle-right" aria-hidden="true"></i></a></li> | ||
<li class="page-item disabled"><a class="page-link disabled" href="#"><i class="fa fa-angle-double-right" aria-hidden="true"></i></a></li> | ||
{% endif %} | ||
</ul> | ||
</nav> | ||
{% endwith %} | ||
{% endif %} |
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,55 @@ | ||
"""template tags interacting with the request's query parameters""" | ||
from django import template | ||
|
||
|
||
register = template.Library() | ||
|
||
|
||
|
||
@register.simple_tag(takes_context=True) | ||
def set_params(context, *interleaved, **pairs): | ||
"""construct a copy of the current request's query parameters, | ||
updated with the given parameters. | ||
parameter keys and values may be specified either as named keyword | ||
argument pairs: | ||
set_params query='cookie' page=2 | ||
and/or as interleaved keys and values (permitting the template | ||
language to specify variable keys): | ||
set_params querykey 'cookie' pagekey nextpage | ||
(which might evaluate as): | ||
set_params 'query' 'cookie' 'page' 2 | ||
""" | ||
request = context['request'] | ||
params = request.GET.copy() | ||
|
||
while interleaved: | ||
try: | ||
(key, value, *interleaved) = interleaved | ||
except ValueError: | ||
raise TypeError('incorrect number of arguments for interleaved parameter pairs') | ||
|
||
params[key] = value | ||
|
||
params.update(pairs) | ||
|
||
return params.urlencode() | ||
|
||
|
||
@register.simple_tag(takes_context=True) | ||
def set_params_path(context, *interleaved, **pairs): | ||
"""construct the current full path (including query), updated by the | ||
given parameters. | ||
(See: ``set_params``.) | ||
""" | ||
request = context['request'] | ||
params = set_params(context, *interleaved, **pairs) | ||
return request.path + '?' + params |
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
Oops, something went wrong.