diff --git a/photologue_custom/templates/photologue/gallery_detail.html b/photologue_custom/templates/photologue/gallery_detail.html index 9a747c3..f8f3ef4 100644 --- a/photologue_custom/templates/photologue/gallery_detail.html +++ b/photologue_custom/templates/photologue/gallery_detail.html @@ -46,13 +46,24 @@
- {% for photo in gallery.public %} + {% for photo in photos %} {{ photo.title }}{% if photo.date_taken %} - {{ photo.date_taken|date }} {{ photo.date_taken|time }}{% endif %} - {{ photo.extented.owner.get_full_name }} diff --git a/photologue_custom/urls.py b/photologue_custom/urls.py index 52fc483..6ada0f6 100644 --- a/photologue_custom/urls.py +++ b/photologue_custom/urls.py @@ -1,11 +1,14 @@ from django.urls import path, re_path from .views import (CustomGalleryArchiveIndexView, - CustomGalleryYearArchiveView, GalleryDownload, TagDetail) + CustomGalleryYearArchiveView, CustomGalleryDetailView, + GalleryDownload, TagDetail) urlpatterns = [ path('tag//', TagDetail.as_view(), name='tag-detail'), path('gallery/', CustomGalleryArchiveIndexView.as_view(), name='pl-gallery-archive'), re_path(r'^gallery/(?P\d{4})/$', CustomGalleryYearArchiveView.as_view(), name='pl-gallery-archive-year'), + path('gallery//', CustomGalleryDetailView.as_view(), name='pl-gallery'), + path('gallery///', CustomGalleryDetailView.as_view(), name='pl-gallery-owner'), path('gallery//download/', GalleryDownload.as_view(), name='gallery-download'), ] diff --git a/photologue_custom/views.py b/photologue_custom/views.py index 0a29748..cb79800 100644 --- a/photologue_custom/views.py +++ b/photologue_custom/views.py @@ -43,6 +43,29 @@ class CustomGalleryYearArchiveView(GalleryYearArchiveView): uses_datetime_field = False # Fix related object access +class CustomGalleryDetailView(DetailView): + """ + Custom gallery detail view to filter on photo owner + """ + queryset = Gallery.objects.on_site().is_public() + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['photos'] = self.object.public() + + # List owners + context['owners'] = [] + for photo in context['photos']: + if photo.extented.owner not in context['owners']: + context['owners'].append(photo.extented.owner) + + # Filter on owner + if 'owner' in self.kwargs: + context['photos'] = context['photos'].filter(extented__owner__id=self.kwargs['owner']) + + return context + + class GalleryDownload(LoginRequiredMixin, DetailView): model = Gallery