From 21a3ab40c50c2436e82198ae184d41a9ca7a9e5d Mon Sep 17 00:00:00 2001 From: Wally Hackenslacker Date: Fri, 27 Mar 2026 21:04:18 -0400 Subject: [PATCH] special-gallery: scope image prev/next/back to special galleries; add tests --- viewer/common.py | 6 +- viewer/directory.py | 2 +- viewer/image.py | 15 +++- viewer/templates/gallery_view.html | 34 ++++++--- viewer/templates/image_view.html | 116 +++++++++++++++++------------ viewer/test_specials.py | 35 +++++++++ 6 files changed, 145 insertions(+), 63 deletions(-) diff --git a/viewer/common.py b/viewer/common.py index 5a4ca85..76d84a0 100644 --- a/viewer/common.py +++ b/viewer/common.py @@ -64,15 +64,15 @@ def append_query(url, query_dict): return url + "?" + urlencode(query_dict) -def gallery_url(path_obj=None, is_dir=False, query_dict=None): +def gallery_url(path_obj=None, is_dir=False, query_dict=None, special=None): if query_dict is None: query_dict = {} if path_obj is None: - base_url = "/gallery/" + base_url = f"/gallery/{special}/" if special is not None else "/gallery/" else: path_text = str(path_obj).replace("\\", "/") - base_url = "/gallery/" + path_text + base_url = (f"/gallery/{special}/" if special is not None else "/gallery/") + path_text if is_dir and not base_url.endswith("/"): base_url += "/" diff --git a/viewer/directory.py b/viewer/directory.py index 3c19147..d984117 100644 --- a/viewer/directory.py +++ b/viewer/directory.py @@ -122,7 +122,7 @@ def render_directory(request, path_text, full_path, special=None): image_data = [] for image in images: rel_path = image.relative_to(settings.GALLERY_ROOT) - image_url = gallery_url(rel_path, False, query_state) + image_url = gallery_url(rel_path, False, query_state, special) thumbnail = None try: diff --git a/viewer/image.py b/viewer/image.py index fa26947..50adef1 100644 --- a/viewer/image.py +++ b/viewer/image.py @@ -115,11 +115,22 @@ def render_image(request, path_text, full_path, special=None): next_url = None if prev_path is not None: rel = prev_path.relative_to(settings.GALLERY_ROOT) - prev_url = gallery_url(rel, False, query_state) + # When viewing from a special gallery, route prev/next through the + # special gallery URL so subsequent navigation preserves the special + # gallery context. Otherwise use the normal gallery URL for the file. + if special is not None: + rel_text = str(rel).replace("\\", "/") + prev_url = append_query(f"/gallery/{special}/{rel_text}/", query_state) + else: + prev_url = gallery_url(rel, False, query_state) if next_path is not None: rel = next_path.relative_to(settings.GALLERY_ROOT) - next_url = gallery_url(rel, False, query_state) + if special is not None: + rel_text = str(rel).replace("\\", "/") + next_url = append_query(f"/gallery/{special}/{rel_text}/", query_state) + else: + next_url = gallery_url(rel, False, query_state) # Back (directory) and Home (root) links and thumbnails dir_rel = None diff --git a/viewer/templates/gallery_view.html b/viewer/templates/gallery_view.html index 467e47e..b03a473 100644 --- a/viewer/templates/gallery_view.html +++ b/viewer/templates/gallery_view.html @@ -49,9 +49,11 @@ Most visited Recently visited - {% if path != '' %} + {% if path != '' or is_special %}
+ {% endif %} + {% if path != '' %} {% if back_thumb %} back thumb @@ -60,7 +62,9 @@ {% endif %} Back + {% endif %} + {% if path != '' or is_special %} {% if home_thumb %} home thumb @@ -125,13 +129,15 @@
-
Favorites - Most visited - Recently visited + Favorites + Most visited + Recently visited + + {% if path != '' or is_special %} +
+ {% endif %} {% if path != '' %} -
- {% if back_thumb %} back thumb @@ -140,7 +146,9 @@ {% endif %} Back + {% endif %} + {% if path != '' or is_special %} {% if home_thumb %} home thumb @@ -265,13 +273,15 @@
-
Favorites - Most visited - Recently visited + Favorites + Most visited + Recently visited + + {% if path != '' or is_special %} +
+ {% endif %} {% if path != '' %} -
- {% if back_thumb %} back thumb @@ -280,7 +290,9 @@ {% endif %} Back + {% endif %} + {% if path != '' or is_special %} {% if home_thumb %} home thumb diff --git a/viewer/templates/image_view.html b/viewer/templates/image_view.html index 1e78dcb..c12e6c1 100644 --- a/viewer/templates/image_view.html +++ b/viewer/templates/image_view.html @@ -36,46 +36,59 @@