Add support for removing keys for a link's kept query string, remove the 'page' key from the active sources links. Closes issue #91.

This commit is contained in:
Roberto Rosario
2015-01-07 02:32:41 -04:00
parent d91a0c1fab
commit e75af75368
2 changed files with 17 additions and 0 deletions

View File

@@ -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

View File

@@ -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),
}