from django.conf import settings from django.core.cache import cache from django.core.paginator import Paginator from django.db.models import Count, F, Q, Sum from django.http import JsonResponse from django.shortcuts import get_object_or_404, redirect from django.urls import reverse from django.views import View from django.views.generic import DetailView, ListView, TemplateView from ..models import Album, Photo, Redir class Main(TemplateView): """Main homepage.""" template_name = "gallery/main.html" def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['canonical_url'] = self.request.build_absolute_uri(reverse('gallery:main_url')) context['latest_albums'] = Album.objects.filter(is_public=True).order_by('-album_date')[:6] return context class About(TemplateView): """Static about page.""" template_name = "gallery/about.html" def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['canonical_url'] = self.request.build_absolute_uri(reverse('gallery:about_url')) return context def redirect_to_album(request, redir_path): """Handles redirect logic for shortened/legacy album URLs.""" redir = get_object_or_404(Redir, path=redir_path) return redirect('gallery:album_url', album_slug=redir.album.slug)