Cleanup routing and remove middleware

This commit is contained in:
Alexandre Iooss 2021-10-23 15:33:14 +02:00
parent 4514d7e020
commit de6088ca5f
7 changed files with 25 additions and 45 deletions

View file

@ -39,7 +39,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
{% if gallery.extended.tags.all %}
<p class="text-muted">
Tags : {% for tag in gallery.extended.tags.all %}
<a class="badge rounded-pill bg-dark text-decoration-none" href="{% url 'tag-detail' tag.slug %}">{{ tag }}</a>
<a class="badge rounded-pill bg-dark text-decoration-none" href="{% url 'photologue:tag-detail' tag.slug %}">{{ tag }}</a>
{% endfor %}
</p>
{% endif %}
@ -49,14 +49,14 @@ SPDX-License-Identifier: GPL-3.0-or-later
<div class="card-header pb-0 border-bottom-0">
<ul class="nav nav-tabs">
<li class="nav-item">
{% url 'pl-gallery' gallery.slug as url %}
{% url 'photologue: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 %}
{% url 'photologue: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>
@ -72,7 +72,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
{% endfor %}
</div>
<div class="card-footer">
<a href="{% url 'gallery-download' gallery.slug %}" class="btn btn-secondary btn-sm">{% trans 'Download all gallery' %}</a>
<a href="{% url 'photologue:pl-gallery-download' gallery.slug %}" class="btn btn-secondary btn-sm">{% trans 'Download all gallery' %}</a>
</div>
</div>
{% endblock %}

View file

@ -1,15 +1,19 @@
from django.urls import path, re_path
from .views import (CustomGalleryArchiveIndexView, CustomGalleryDetailView,
CustomGalleryYearArchiveView, GalleryDownload,
GalleryUpload, TagDetail)
CustomGalleryYearArchiveView, CustomPhotoDetailView,
GalleryDownload, GalleryUpload, TagDetail)
# Rather than using photologue default router, we redefine our own router
# with login and permission checks.
app_name = 'photologue'
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'),
path('upload/', GalleryUpload.as_view(), name='gallery-upload'),
path('gallery/<slug:slug>/download/', GalleryDownload.as_view(), name='pl-gallery-download'),
path('photo/<slug:slug>/', CustomPhotoDetailView.as_view(), name='pl-photo'),
path('upload/', GalleryUpload.as_view(), name='pl-gallery-upload'),
]

View file

@ -16,7 +16,8 @@ from django.utils.text import slugify
from django.views.generic.detail import DetailView
from django.views.generic.edit import FormView
from photologue.models import Gallery, Photo
from photologue.views import GalleryArchiveIndexView, GalleryYearArchiveView
from photologue.views import (GalleryArchiveIndexView, GalleryYearArchiveView,
PhotoDetailView)
from PIL import Image
from taggit.models import Tag
@ -39,7 +40,7 @@ class TagDetail(LoginRequiredMixin, DetailView):
return context
class CustomGalleryArchiveIndexView(GalleryArchiveIndexView):
class CustomGalleryArchiveIndexView(LoginRequiredMixin, GalleryArchiveIndexView):
"""
Override to use event date
"""
@ -47,7 +48,7 @@ class CustomGalleryArchiveIndexView(GalleryArchiveIndexView):
uses_datetime_field = False # Fix related object access
class CustomGalleryYearArchiveView(GalleryYearArchiveView):
class CustomGalleryYearArchiveView(LoginRequiredMixin, GalleryYearArchiveView):
"""
Override to use event date
"""
@ -55,7 +56,7 @@ class CustomGalleryYearArchiveView(GalleryYearArchiveView):
uses_datetime_field = False # Fix related object access
class CustomGalleryDetailView(DetailView):
class CustomGalleryDetailView(LoginRequiredMixin, DetailView):
"""
Custom gallery detail view to filter on photo owner
"""
@ -102,13 +103,17 @@ class GalleryDownload(LoginRequiredMixin, DetailView):
return response
class CustomPhotoDetailView(LoginRequiredMixin, PhotoDetailView):
pass
class GalleryUpload(PermissionRequiredMixin, FormView):
"""
Form to upload new photos in a gallery
"""
form_class = UploadForm
template_name = "photologue/upload.html"
success_url = reverse_lazy("gallery-upload")
success_url = reverse_lazy("photologue:pl-gallery-upload")
permission_required = 'photologue.add_gallery'
def form_valid(self, form):