From 8c95843553cbeb10f1fd6c77767d44997f90c1e6 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Wed, 25 Oct 2023 15:07:51 +0200 Subject: [PATCH 1/1] Allow ignored get vars. --- fnp_django_pagination/__init__.py | 2 +- .../templatetags/pagination_tags.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/fnp_django_pagination/__init__.py b/fnp_django_pagination/__init__.py index c6033e7..b32eaae 100644 --- a/fnp_django_pagination/__init__.py +++ b/fnp_django_pagination/__init__.py @@ -34,4 +34,4 @@ tools throughout a django application. """ -__version__ = (2, 2, 9, "final", 0) +__version__ = (2, 2, 10, "final", 0) diff --git a/fnp_django_pagination/templatetags/pagination_tags.py b/fnp_django_pagination/templatetags/pagination_tags.py index 0845501..b47bd12 100644 --- a/fnp_django_pagination/templatetags/pagination_tags.py +++ b/fnp_django_pagination/templatetags/pagination_tags.py @@ -214,8 +214,9 @@ def do_paginate(parser, token): argv = token.split_contents() argc = len(argv) template = None - window=DEFAULT_WINDOW - margin=DEFAULT_MARGIN + window = DEFAULT_WINDOW + margin = DEFAULT_MARGIN + ignored_vars = [] i = 1 while i < argc: if argv[i] == 'using': @@ -227,14 +228,17 @@ def do_paginate(parser, token): elif argv[i] == 'margin': margin = argv[i + 1] i += 2 + elif argv[i] == 'ignore': + ignored_vars.append(argv[i + 1]) + i += 2 else: raise TemplateSyntaxError( "Invalid syntax. Proper usage of this tag is: " "{% paginate [using \"TEMPLATE\"] %}") - return PaginateNode(template, window, margin) + return PaginateNode(template, window, margin, ignored_vars) -def paginate(context, window=DEFAULT_WINDOW, margin=DEFAULT_MARGIN): +def paginate(context, window=DEFAULT_WINDOW, margin=DEFAULT_MARGIN, ignored_vars=None): """ Renders the ``pagination/pagination.html`` template, resulting in a Digg-like display of the available pages, given the current page. If there @@ -349,6 +353,10 @@ def paginate(context, window=DEFAULT_WINDOW, margin=DEFAULT_MARGIN): } if 'request' in context: getvars = context['request'].GET.copy() + if ignored_vars: + for v in ignored_vars: + if v in getvars: + del getvars[v] if 'page%s' % page_suffix in getvars: del getvars['page%s' % page_suffix] if len(getvars.keys()) > 0: -- 2.20.1