Skip to content

Commit 995777c

Browse files
committed
Fix missing other GET params in anchors
1 parent 002aa24 commit 995777c

1 file changed

Lines changed: 10 additions & 13 deletions

File tree

  • webstack_django_sorting/templatetags

webstack_django_sorting/templatetags/common.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
"""
22
Common to Django tags (sorting_tags) and Jinja2 globals (jinja2_globals)
33
"""
4-
from urllib.parse import urlencode
54
from operator import attrgetter
65

76
from .settings import SORT_DIRECTIONS
87

98

109
def render_sort_anchor(request, field_name, title):
11-
sort_by = request.GET.get("sort", "")
10+
get_params = request.GET.copy()
11+
sort_by = get_params.get("sort", None)
1212
if sort_by == field_name:
1313
# Render anchor link to next direction
14-
sort_direction = SORT_DIRECTIONS[request.GET.get("dir", "")]
15-
next_direction_code = sort_direction["next"]
16-
icon = sort_direction["icon"]
14+
current_direction = SORT_DIRECTIONS[get_params.get("dir", "")]
15+
icon = current_direction["icon"]
16+
next_direction_code = current_direction["next"]
1717
else:
18-
# Just a fast code path
19-
next_direction_code = "asc"
2018
icon = ""
19+
next_direction_code = "asc"
2120

22-
url_sort_by = urlencode({"sort": field_name})
23-
url_append = f"?{url_sort_by}"
24-
if next_direction_code:
25-
url_sort_direction = urlencode({"dir": next_direction_code})
26-
url_append += f"&{url_sort_direction}"
27-
21+
# Not usual dict (can't update to replace)
22+
get_params["sort"] = field_name
23+
get_params["dir"] = next_direction_code
24+
url_append = "?" + get_params.urlencode() if get_params else ""
2825
return f'<a href="{request.path}{url_append}" title="{title}">{title}{icon}</a>'
2926

3027

0 commit comments

Comments
 (0)