Added model for special galleries.

This commit is contained in:
Miguel Astor
2026-03-24 15:06:48 -04:00
parent 77d83c58d1
commit 5a6632491a
5 changed files with 122 additions and 3 deletions

View File

@@ -8,13 +8,16 @@ import datetime
# Django imports.
from django.http import HttpResponseNotFound
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.conf import settings
from django.utils import timezone
# Third-party
from PIL import Image
# Project imports.
from .models import Image as Im
from .common import (
normalize_sort,
normalize_theme,
@@ -34,6 +37,20 @@ def render_image(request, path_text, full_path):
Renders the view corresponding to an image file.
"""
try:
img = Im.objects.get(path=full_path, user=request.user)
if request.method == 'POST':
img.favorite = not img.favorite
except Im.DoesNotExist:
img = Im(path=full_path, user=request.user)
finally:
img.last_visited = timezone.now()
img.visits = img.visits + 1
img.save()
# Preserve query state (sort, search, theme) similar to gallery view
search_text = request.GET.get("search", "").strip()
sort_key = normalize_sort(request.GET.get("sort", "abc"))
@@ -177,6 +194,9 @@ def render_image(request, path_text, full_path):
"filesize": human_size(filesize),
"created": fmt_ts(created_ts),
"modified": fmt_ts(modified_ts),
"visits": img.visits,
"visited": fmt_ts(img.last_visited.timestamp()),
"favorite": img.favorite
},
"breadcrumbs": breadcrumbs,
"theme": theme,
@@ -186,6 +206,7 @@ def render_image(request, path_text, full_path):
"theme_toggle_url": gallery_url(
Path(dir_path_text) if dir_path_text != "" else None, True, theme_query
),
"path": path_text,
}
from .common import SORT_LABELS