diff --git a/CHANGELOG.txt b/CHANGELOG.txt index f65c3c6f7..e29ee3843 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -30,6 +30,7 @@ Changelog * Fix: `InlinePanel` now accepts a `classname` parameter as per the documentation (emg36, Matt Westcott) * Fix: Disabled use of escape key to revert content of rich text fields, which could cause accidental data loss (Matt Westcott) * Fix: Setting `USE_THOUSAND_SEPARATOR = True` no longer breaks the rendering of numbers in JS code for InlinePanel (Mattias Loverot, Matt Westcott) + * Fix: Images / documents pagination now preserves GET parameters (Bojan Mihelac) 1.6.3 (30.09.2016) diff --git a/docs/releases/1.7.rst b/docs/releases/1.7.rst index 7af821236..533cf3ad9 100644 --- a/docs/releases/1.7.rst +++ b/docs/releases/1.7.rst @@ -65,6 +65,7 @@ Bug fixes * ``InlinePanel`` now accepts a ``classname`` parameter as per the documentation (emg36, Matt Westcott) * Disabled use of escape key to revert content of rich text fields, which could cause accidental data loss (Matt Westcott) * Setting ``USE_THOUSAND_SEPARATOR = True`` no longer breaks the rendering of numbers in JS code for InlinePanel (Mattias Loverot, Matt Westcott) + * Images / documents pagination now preserves GET parameters (Bojan Mihelac) Upgrade considerations diff --git a/wagtail/utils/pagination.py b/wagtail/utils/pagination.py index f144025be..061396e59 100644 --- a/wagtail/utils/pagination.py +++ b/wagtail/utils/pagination.py @@ -1,6 +1,9 @@ from __future__ import absolute_import, unicode_literals from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator +from django.utils.http import urlencode +from django.utils.six.moves.urllib.parse import parse_qs + DEFAULT_PAGE_KEY = 'p' @@ -17,3 +20,20 @@ def paginate(request, items, page_key=DEFAULT_PAGE_KEY, per_page=20): page = paginator.page(paginator.num_pages) return paginator, page + + +def replace_page_in_query(query, page_number, page_key=DEFAULT_PAGE_KEY): + """ + Replaces ``page_key`` from query string with ``page_number``. + + >>> replace_page_in_query("p=1&key=value", 2) + 'p=2&key=value' + >>> replace_page_in_query("p=1&key=value", None) + 'key=value' + """ + getvars = parse_qs(query) + if page_number is None: + getvars.pop(page_key, None) + else: + getvars[page_key] = page_number + return urlencode(getvars, True) diff --git a/wagtail/wagtailadmin/templates/wagtailadmin/shared/pagination_nav.html b/wagtail/wagtailadmin/templates/wagtailadmin/shared/pagination_nav.html index ca3e4b073..cf84af4b9 100644 --- a/wagtail/wagtailadmin/templates/wagtailadmin/shared/pagination_nav.html +++ b/wagtail/wagtailadmin/templates/wagtailadmin/shared/pagination_nav.html @@ -1,4 +1,5 @@ {% load i18n %} +{% load wagtailadmin_tags %} {% if not is_ajax %} {% comment %} HACK: This template expects to be passed a 'linkurl' parameter, containing a URL name @@ -8,9 +9,15 @@ of the form "?q=123", implicitly preserving the current URL path. Using the {% url ... as ... %} form of the tag ensures that this fails silently, rather than throwing a NoReverseMatch exception. + + If 'linkurl' is not passed, it will instead preserve the current URL and parameters, + just replacing the 'p' parameter. {% endcomment %} - {% url linkurl as url_to_use %} + {% if linkurl %} + {% url linkurl as url_to_use %} + {% endif %} {% endif %} +
{% blocktrans with page_num=items.number total_pages=items.paginator.num_pages %}Page {{ page_num }} of {{ total_pages }}.{% endblocktrans %}