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 %}