|
9 | 9 | from . import settings |
10 | 10 |
|
11 | 11 |
|
12 | | -def render_sort_anchor(request, field_name, title): |
| 12 | +def render_sort_anchor(request, field_name, title, default_direction): |
13 | 13 | get_params = request.GET.copy() |
14 | | - sort_by = get_params.get("sort", None) |
| 14 | + sort_by = get_params.get("sort", None) |
15 | 15 | if sort_by == field_name: |
16 | | - # Render anchor link to next direction |
17 | | - current_direction = settings.SORT_DIRECTIONS.get( |
18 | | - get_params.get("dir", ""), settings.SORT_DIRECTIONS[""] |
19 | | - ) |
20 | | - icon = current_direction["icon"] |
21 | | - next_direction_code = current_direction["next"] |
| 16 | + |
| 17 | + dir = get_params.get("dir") |
| 18 | + |
| 19 | + if dir == "asc": |
| 20 | + icon = settings.DEFAULT_SORT_UP |
| 21 | + elif dir == "desc": |
| 22 | + icon = settings.DEFAULT_SORT_DOWN |
| 23 | + else: |
| 24 | + icon = "" |
| 25 | + |
| 26 | + # Mapping of direction transitions based on the default sort direction |
| 27 | + transition_map = { |
| 28 | + "asc": {"asc": "desc", "desc": "", "": "asc"}, |
| 29 | + "desc": {"desc": "asc", "asc": "", "": "desc"} |
| 30 | + } |
| 31 | + next_direction_code = transition_map[default_direction].get(dir, "") |
| 32 | + |
22 | 33 | else: |
23 | 34 | icon = "" |
24 | | - next_direction_code = "asc" |
| 35 | + next_direction_code = default_direction |
25 | 36 |
|
26 | 37 | # Not usual dict (can't update to replace) |
27 | 38 | get_params["sort"] = field_name |
|
0 commit comments