feat(viewer): persist theme/sort via toggle view; use middleware-provided theme/sort in views and templates

This commit is contained in:
Miguel Astor
2026-03-25 04:43:35 -04:00
parent 8719be3227
commit 73b538b698
5 changed files with 107 additions and 24 deletions

View File

@@ -170,16 +170,22 @@ def build_sort_options(request, search_text, sort_key, theme):
options = []
for option_key, label in SORT_OPTIONS:
query = {"sort": option_key, "theme": theme}
# Build a URL that points to the settings toggle endpoint which will
# persist the chosen sort (and optionally theme) in the user's
# UserSettings and then redirect back to the current view. Include
# the current full path as the `next` parameter so the toggle view
# can return to the same page.
query = {"next": request.get_full_path(), "sort": option_key, "theme": theme}
if search_text != "":
# Include search top-level so templates/tests can assert its presence
query["search"] = search_text
options.append(
{
"key": option_key,
"label": label,
"url": append_query(request.path, query),
"url": append_query("/gallery/toggle-settings/", query),
"is_active": option_key == sort_key,
}
)