Facets can now be toggled off again, refs #255

This commit is contained in:
Simon Willison 2018-05-15 07:11:52 -03:00 committed by Simon Willison
commit 1dc94f6eaa
4 changed files with 13 additions and 3 deletions

View file

@ -166,10 +166,18 @@ def path_with_added_args(request, args, path=None):
def path_with_removed_args(request, args, path=None):
# args can be a dict or a set
path = path or request.path
current = []
if isinstance(args, set):
def should_remove(key, value):
return key in args
elif isinstance(args, dict):
# Must match key AND value
def should_remove(key, value):
return args.get(key) == value
for key, value in urllib.parse.parse_qsl(request.query_string):
if key not in args:
if not should_remove(key, value):
current.append((key, value))
query_string = urllib.parse.urlencode(current)
if query_string: