mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
_sort/_next links now use new path_with_replaced_args method
This commit is contained in:
parent
2f81552cd2
commit
a82175276c
5 changed files with 85 additions and 4 deletions
|
|
@ -177,6 +177,22 @@ def path_with_removed_args(request, args, path=None):
|
|||
return path + query_string
|
||||
|
||||
|
||||
def path_with_replaced_args(request, args, path=None):
|
||||
path = path or request.path
|
||||
if isinstance(args, dict):
|
||||
args = args.items()
|
||||
keys_to_replace = {p[0] for p in args}
|
||||
current = []
|
||||
for key, value in urllib.parse.parse_qsl(request.query_string):
|
||||
if key not in keys_to_replace:
|
||||
current.append((key, value))
|
||||
current.extend([p for p in args if p[1] is not None])
|
||||
query_string = urllib.parse.urlencode(current)
|
||||
if query_string:
|
||||
query_string = '?{}'.format(query_string)
|
||||
return path + query_string
|
||||
|
||||
|
||||
def path_with_ext(request, ext):
|
||||
path = request.path
|
||||
path += ext
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue