special galleries: helper module, renderers, templates & urls; hide back in special views; highlight active special
This commit is contained in:
@@ -20,6 +20,9 @@ from .image import render_image
|
||||
from .models import UserSettings
|
||||
|
||||
|
||||
SPECIALS = ['favorites', 'most-visited', 'recent']
|
||||
|
||||
|
||||
@login_required
|
||||
def index(request):
|
||||
return redirect("gallery_view_root")
|
||||
@@ -51,6 +54,46 @@ def gallery_view(request, path=None):
|
||||
return render_image(request, path_text, candidate)
|
||||
|
||||
|
||||
@login_required
|
||||
def special_gallery_view(request, gallery, path=None):
|
||||
"""
|
||||
Shows a list of subdirectories and image files inside the given special gallery.
|
||||
Available special galleries are: (1) favorites; (2) most visited; (3) recently visited.
|
||||
"""
|
||||
|
||||
root = settings.GALLERY_ROOT.resolve()
|
||||
|
||||
if gallery not in SPECIALS:
|
||||
return HttpResponseNotFound("Not found")
|
||||
|
||||
try:
|
||||
candidate = root.joinpath(path).resolve() if path is not None else root
|
||||
candidate.relative_to(root)
|
||||
except Exception:
|
||||
return HttpResponseNotFound("Not found")
|
||||
|
||||
path_text = path if path is not None else ""
|
||||
|
||||
if path is not None:
|
||||
# Special galleries only have a logical root directory.
|
||||
# When there is a valid sub-directory path inside the gallery root
|
||||
# in the request then redirect to the base special gallery.
|
||||
if candidate.is_dir():
|
||||
return redirect('special_gallery_view_path', gallery, None, permanent=True)
|
||||
|
||||
else:
|
||||
# When there is no path to render, then go to the corresponding special gallery root.
|
||||
return render_directory(request, path_text, candidate, gallery)
|
||||
|
||||
# Fail if the requested image doesn' exist.
|
||||
if not candidate.exists():
|
||||
return HttpResponseNotFound("Not found")
|
||||
|
||||
# Images are rendered normally, with a control to ensure the back, next and previous buttons
|
||||
# use the special gallery.
|
||||
return render_image(request, path_text, candidate, gallery)
|
||||
|
||||
|
||||
@login_required
|
||||
def toggle_settings(request):
|
||||
"""Persist theme and/or sort for the current user and redirect back.
|
||||
|
||||
Reference in New Issue
Block a user