Filter gallery by photo owner
This commit is contained in:
parent
740cbc9df0
commit
cc3ba4a492
3 changed files with 40 additions and 3 deletions
|
|
@ -46,13 +46,24 @@
|
|||
<div class="card-header pb-0 border-bottom-0">
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" href="#">{% trans "All pictures" %}</a>
|
||||
{% url 'pl-gallery' gallery.slug as url %}
|
||||
<a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}">
|
||||
{% trans "All pictures" %}
|
||||
</a>
|
||||
</li>
|
||||
{% for owner in owners %}
|
||||
<li class="nav-item">
|
||||
{% url 'pl-gallery-owner' slug=gallery.slug owner=owner.id as url %}
|
||||
<a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}">
|
||||
{% if owner.get_full_name %}{{ owner.get_full_name }}{% else %}{{ owner.username }}{% endif %}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div id="lightgallery">
|
||||
{% for photo in gallery.public %}
|
||||
{% for photo in photos %}
|
||||
<a href="{{ photo.get_absolute_url }}" data-src="{{ photo.get_display_url }}" data-download-url="{{ photo.image.url }}">
|
||||
<img src="{{ photo.get_thumbnail_url }}" class="img-thumbnail" alt="{{ photo.title }}{% if photo.date_taken %} - {{ photo.date_taken|date }} {{ photo.date_taken|time }}{% endif %} - {{ photo.extented.owner.get_full_name }}">
|
||||
</a>
|
||||
|
|
|
|||
|
|
@ -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/<slug:slug>/', TagDetail.as_view(), name='tag-detail'),
|
||||
path('gallery/', CustomGalleryArchiveIndexView.as_view(), name='pl-gallery-archive'),
|
||||
re_path(r'^gallery/(?P<year>\d{4})/$', CustomGalleryYearArchiveView.as_view(), name='pl-gallery-archive-year'),
|
||||
path('gallery/<slug:slug>/', CustomGalleryDetailView.as_view(), name='pl-gallery'),
|
||||
path('gallery/<slug:slug>/<int:owner>/', CustomGalleryDetailView.as_view(), name='pl-gallery-owner'),
|
||||
path('gallery/<slug:slug>/download/', GalleryDownload.as_view(), name='gallery-download'),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue