From 1d72cc06fe88f28e344ff894e41544cd0ce65a57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20=20MENAGER?= <herve.menager@pasteur.fr> Date: Mon, 13 Nov 2017 15:45:56 +0100 Subject: [PATCH] correct pagination with filters on using custom tag custom tag copied from https://stackoverflow.com/a/17068299 Former-commit-id: 7fc0c4824eb0d75e0f4b01d3589cba92f6af490d --- ippisite/ippidb/templates/compound_list.html | 6 +++--- ippisite/ippidb/templatetags/__init__.py | 0 ippisite/ippidb/templatetags/customtags.py | 9 +++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 ippisite/ippidb/templatetags/__init__.py create mode 100644 ippisite/ippidb/templatetags/customtags.py diff --git a/ippisite/ippidb/templates/compound_list.html b/ippisite/ippidb/templates/compound_list.html index 42461ec9..a189f2c6 100644 --- a/ippisite/ippidb/templates/compound_list.html +++ b/ippisite/ippidb/templates/compound_list.html @@ -1,5 +1,5 @@ {% extends "base.html" %} - +{% load customtags %} {% block title %}compound{% endblock %} @@ -46,7 +46,7 @@ <ul class="pagination justify-content-end"> {% if compounds.has_previous %} <li class="page-item"> - <a class="page-link" href="?page={{ compounds.previous_page_number }}" tabindex="-1">Previous</a> + <a class="page-link" href="?{% url_replace request 'page' compounds.previous_page_number %}" tabindex="-1">Previous</a> </li> {% endif %} @@ -56,7 +56,7 @@ {% if compounds.has_next %} <li class="page-item"> - <a class="page-link" href="?page={{ compounds.next_page_number }}" tabindex="-1">Next</a> + <a class="page-link" href="?{% url_replace request 'page' compounds.next_page_number %}" tabindex="-1">Next</a> </li> {% endif %} </ul> diff --git a/ippisite/ippidb/templatetags/__init__.py b/ippisite/ippidb/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ippisite/ippidb/templatetags/customtags.py b/ippisite/ippidb/templatetags/customtags.py new file mode 100644 index 00000000..c01874f8 --- /dev/null +++ b/ippisite/ippidb/templatetags/customtags.py @@ -0,0 +1,9 @@ +from django import template + +register = template.Library() + +@register.simple_tag +def url_replace(request, field, value): + dict_ = request.GET.copy() + dict_[field] = value + return dict_.urlencode() -- GitLab