From e75af7536878a992fb8f0b8515c6c4f8320f2582 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Wed, 7 Jan 2015 02:32:41 -0400 Subject: [PATCH] Add support for removing keys for a link's kept query string, remove the 'page' key from the active sources links. Closes issue #91. --- .../navigation/templatetags/navigation_tags.py | 16 ++++++++++++++++ mayan/apps/sources/views.py | 1 + 2 files changed, 17 insertions(+) diff --git a/mayan/apps/navigation/templatetags/navigation_tags.py b/mayan/apps/navigation/templatetags/navigation_tags.py index 191f88e05b..c188054956 100644 --- a/mayan/apps/navigation/templatetags/navigation_tags.py +++ b/mayan/apps/navigation/templatetags/navigation_tags.py @@ -91,6 +91,14 @@ def resolve_links(context, links, current_view, current_path, parsed_query_strin else: new_link['url'] = reverse(link['view'], args=args) if link.get('keep_query', False): + try: + for key in link.get('remove_from_query', []): + del parsed_query_string[key] + except KeyError: + # We were asked to remove a key not found in the + # query string, that is not fatal + pass + new_link['url'] = urlquote(new_link['url'], parsed_query_string) except NoReverseMatch as exception: new_link['url'] = '#' @@ -104,6 +112,14 @@ def resolve_links(context, links, current_view, current_path, parsed_query_strin else: new_link['url'] = link['url'] % args if link.get('keep_query', False): + try: + for key in link.get('remove_from_query', []): + del parsed_query_string[key] + except KeyError: + # We were asked to remove a key not found in the + # query string, that is not fatal + pass + new_link['url'] = urlquote(new_link['url'], parsed_query_string) else: new_link['active'] = False diff --git a/mayan/apps/sources/views.py b/mayan/apps/sources/views.py index 427e5e1c23..fb0fd1b3e8 100644 --- a/mayan/apps/sources/views.py +++ b/mayan/apps/sources/views.py @@ -67,6 +67,7 @@ def get_tab_link_for_source(source, document=None): 'view': view, 'args': args, 'keep_query': True, + 'remove_from_query': ['page'], 'conditional_highlight': conditional_highlight_factory(source), }