special galleries: helper module, renderers, templates & urls; hide back in special views; highlight active special

This commit is contained in:
2026-03-27 20:09:35 -04:00
parent 24c1c96f19
commit 532690a329
8 changed files with 252 additions and 64 deletions

View File

@@ -31,9 +31,10 @@ from .common import (
is_image_file,
make_thumbnail,
)
from .specials import get_special_paths, special_name
def render_image(request, path_text, full_path):
def render_image(request, path_text, full_path, special=None):
"""
Renders the view corresponding to an image file.
"""
@@ -67,19 +68,26 @@ def render_image(request, path_text, full_path):
image = Path("/imgs/").joinpath(path_text)
img_dir = full_path.parent
try:
entries = [
entry
for entry in img_dir.iterdir()
if entry.is_file() and not entry.is_symlink() and is_image_file(entry)
]
except OSError:
return HttpResponseNotFound("Not found")
if special is not None:
# Use the special gallery ordering for prev/next navigation
images_sorted = get_special_paths(request.user, special)
# If favorites, respect client sort; otherwise keep DB ordering
if special == "favorites":
images_sorted = sort_images(images_sorted, sort_key)
else:
try:
entries = [
entry
for entry in img_dir.iterdir()
if entry.is_file() and not entry.is_symlink() and is_image_file(entry)
]
except OSError:
return HttpResponseNotFound("Not found")
# Sort siblings according to requested sort mode
images_sorted = sort_images(entries, sort_key)
# Sort siblings according to requested sort mode
images_sorted = sort_images(entries, sort_key)
# Find index of current image
# Find index of current image within the resolved list
try:
index = next(i for i, p in enumerate(images_sorted) if p.name == full_path.name)
except StopIteration:
@@ -122,10 +130,15 @@ def render_image(request, path_text, full_path):
except Exception:
dir_text = ""
back_url = gallery_url(
Path(dir_text) if dir_text != "" else None, True, query_state
)
back_thumb = get_first_image_thumbnail_url(full_path.parent)
# For special galleries hide the Back control but still present Home
if special is not None:
back_url = None
back_thumb = None
else:
back_url = gallery_url(
Path(dir_text) if dir_text != "" else None, True, query_state
)
back_thumb = get_first_image_thumbnail_url(full_path.parent)
home_url = gallery_url(None, True, query_state)
home_thumb = get_first_image_thumbnail_url(settings.GALLERY_ROOT)
@@ -169,11 +182,19 @@ def render_image(request, path_text, full_path):
except Exception:
return None
# Breadcrumbs: include directory breadcrumbs then append file name as label-only
# build_breadcrumbs expects a path_text representing directories only
dir_path_text = dir_text if dir_text != "" else ""
breadcrumbs = build_breadcrumbs(dir_path_text, query_state)
breadcrumbs.append({"label": full_path.name, "path": None})
# Breadcrumbs
if special is not None:
# SPECIAL NAME / IMAGE
breadcrumbs = [
{"label": special_name(special), "path": None},
{"label": full_path.name, "path": None},
]
else:
# include directory breadcrumbs then append file name as label-only
# build_breadcrumbs expects a path_text representing directories only
dir_path_text = dir_text if dir_text != "" else ""
breadcrumbs = build_breadcrumbs(dir_path_text, query_state)
breadcrumbs.append({"label": full_path.name, "path": None})
next_theme = "light" if theme == "dark" else "dark"
theme_query = {
@@ -216,6 +237,7 @@ def render_image(request, path_text, full_path):
"sort_options": build_sort_options(request, search_text, sort_key, theme),
"theme_toggle_url": append_query("/gallery/toggle-settings/", theme_query),
"path": path_text,
"is_special": special is not None,
}
from .common import SORT_LABELS