From d59fb154b66f9f8bc79cdc6498ba37cf1b1a9ad6 Mon Sep 17 00:00:00 2001
From: Alexandre Iooss
Date: Thu, 23 Sep 2021 11:05:04 +0200
Subject: [PATCH] Add detail page for tags
---
photo21/templates/index.html | 2 +-
photo21/urls.py | 2 ++
.../templates/photologue/gallery_detail.html | 2 +-
.../templates/taggit/tag_detail.html | 16 ++++++++++++++
photologue_custom/urls.py | 7 +++++++
photologue_custom/views.py | 21 +++++++++++++++++++
6 files changed, 48 insertions(+), 2 deletions(-)
create mode 100644 photologue_custom/templates/taggit/tag_detail.html
create mode 100644 photologue_custom/urls.py
diff --git a/photo21/templates/index.html b/photo21/templates/index.html
index ae0b73e..4045b1d 100644
--- a/photo21/templates/index.html
+++ b/photo21/templates/index.html
@@ -19,7 +19,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
Si vous souhaitez qu'une photo soit supprimée, signalez le nous :
-
diff --git a/photo21/urls.py b/photo21/urls.py
index c15ca5f..e705827 100644
--- a/photo21/urls.py
+++ b/photo21/urls.py
@@ -23,9 +23,11 @@ from .views import IndexView
urlpatterns = [
path('', IndexView.as_view(), name='index'),
path('photologue/', include('photologue.urls', namespace='photologue')),
+ path('photologue_custom/', include('photologue_custom.urls')),
path('accounts/', include('django.contrib.auth.urls')),
path('i18n/', include('django.conf.urls.i18n')),
path('admin/', admin.site.urls),
+ path('admin/doc/', include('django.contrib.admindocs.urls')),
]
if settings.DEBUG:
diff --git a/photologue_custom/templates/photologue/gallery_detail.html b/photologue_custom/templates/photologue/gallery_detail.html
index 368da46..729ad37 100644
--- a/photologue_custom/templates/photologue/gallery_detail.html
+++ b/photologue_custom/templates/photologue/gallery_detail.html
@@ -26,7 +26,7 @@
{% if gallery.extended.tags.all %}
Tags : {% for tag in gallery.extended.tags.all %}
- {{ tag }}
+ {{ tag }}
{% endfor %}
{% endif %}
diff --git a/photologue_custom/templates/taggit/tag_detail.html b/photologue_custom/templates/taggit/tag_detail.html
new file mode 100644
index 0000000..5580877
--- /dev/null
+++ b/photologue_custom/templates/taggit/tag_detail.html
@@ -0,0 +1,16 @@
+{% extends "base.html" %}
+{% load i18n %}
+
+{% block title %}{{ object.name }}{% endblock %}
+
+{% block content %}
+
Tag : {{ object.name }}
+
+
+ {% for gallery in galleries %}
+
+ {% include "photologue/includes/gallery_sample.html" %}
+
+ {% endfor %}
+
+{% endblock %}
diff --git a/photologue_custom/urls.py b/photologue_custom/urls.py
new file mode 100644
index 0000000..741b84c
--- /dev/null
+++ b/photologue_custom/urls.py
@@ -0,0 +1,7 @@
+from django.urls import path
+
+from .views import TagDetail
+
+urlpatterns = [
+ path('tags/
/', TagDetail.as_view(), name='tag-detail'),
+]
diff --git a/photologue_custom/views.py b/photologue_custom/views.py
index e69de29..647137b 100644
--- a/photologue_custom/views.py
+++ b/photologue_custom/views.py
@@ -0,0 +1,21 @@
+# Copyright (C) 2021 by BDE ENS Paris-Saclay
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+from django.contrib.auth.mixins import LoginRequiredMixin
+from django.views.generic import DetailView
+from taggit.models import Tag
+from photologue.models import Gallery
+
+
+class TagDetail(LoginRequiredMixin, DetailView):
+ model = Tag
+
+ def get_context_data(self, **kwargs):
+ """
+ Insert the single object into the context dict.
+ """
+ current_tag = self.get_object().slug
+ context = super().get_context_data(**kwargs)
+ context['galleries'] = Gallery.objects.on_site().is_public() \
+ .filter(extended__tags__name=current_tag)
+ return context