Merge branch 'erdnaxe-april22' into 'master'
April 2022 shower See merge request bde/photo21!26
This commit is contained in:
commit
a96b39007b
4 changed files with 59 additions and 59 deletions
|
|
@ -42,11 +42,6 @@ ADMINS = [
|
||||||
("admin", "photos-admin@lists.crans.org"),
|
("admin", "photos-admin@lists.crans.org"),
|
||||||
]
|
]
|
||||||
|
|
||||||
# Managers receive uploads notification
|
|
||||||
MANAGERS = [
|
|
||||||
('admin', 'photos-admin@lists.crans.org'),
|
|
||||||
]
|
|
||||||
|
|
||||||
# Use secure cookies in production
|
# Use secure cookies in production
|
||||||
SESSION_COOKIE_SECURE = not DEBUG
|
SESSION_COOKIE_SECURE = not DEBUG
|
||||||
CSRF_COOKIE_SECURE = not DEBUG
|
CSRF_COOKIE_SECURE = not DEBUG
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
{% block title %}{% trans "Latest photo galleries" %}{% endblock %}
|
{% block title %}{% trans "Latest photo galleries" %}{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-12">
|
|
||||||
<h1>{% trans "Latest photo galleries" %}</h1>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<aside class="col-md-2">
|
<aside class="col-md-2">
|
||||||
<h5>{% trans "Filter by year" %}</h5>
|
<h5>{% trans "Filter by year" %}</h5>
|
||||||
|
|
|
||||||
|
|
@ -9,27 +9,27 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
{% block title %}{% blocktrans with show_year=year|date:"Y" %}Galleries for {{ show_year }}{% endblocktrans %}{% endblock %}
|
{% block title %}{% blocktrans with show_year=year|date:"Y" %}Galleries for {{ show_year }}{% endblocktrans %}{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-12">
|
<aside class="col-md-2">
|
||||||
<h1>{% blocktrans with show_year=year|date:"Y" %}Galleries for {{ show_year }}{% endblocktrans %}</h1>
|
<h5>{% trans "Filter by year" %}</h5>
|
||||||
</div>
|
<div class="list-group">
|
||||||
</div>
|
{% for date in date_list %}
|
||||||
<div class="row">
|
<a class="list-group-item list-group-item-action{% if date == year %} active{% endif %}" href="{% url 'photologue:pl-gallery-archive-year' date.year %}">{{ date|date:"Y" }}</a>
|
||||||
<aside class="col-md-2">
|
{% endfor %}
|
||||||
<a href="{% url 'photologue:pl-gallery-archive' %}">⬅ {% trans "View all galleries" %}</a>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
<main class="col-md-10">
|
<main class="col-md-10">
|
||||||
{% if object_list %}
|
{% if object_list %}
|
||||||
<div class="row mb-2">
|
<div class="row mb-2">
|
||||||
{% for gallery in object_list %}
|
{% for gallery in object_list %}
|
||||||
<div class="col-6 col-md-3 mb-2">
|
<div class="col-6 col-md-3 mb-2">
|
||||||
{% include "photologue/includes/gallery_sample.html" %}
|
{% include "photologue/includes/gallery_sample.html" %}
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% endfor %}
|
||||||
<p>{% trans "No galleries were found." %}</p>
|
</div>
|
||||||
{% endif %}
|
{% else %}
|
||||||
</main>
|
<p>{% trans "No galleries were found." %}</p>
|
||||||
</div>
|
{% endif %}
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
@ -9,7 +9,7 @@ from pathlib import Path
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
|
||||||
from django.core.mail import mail_managers
|
from django.core.mail import mail_admins
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
|
|
@ -27,6 +27,7 @@ from .models import Gallery, Photo, Tag
|
||||||
class GalleryDateView(LoginRequiredMixin):
|
class GalleryDateView(LoginRequiredMixin):
|
||||||
model = Gallery
|
model = Gallery
|
||||||
date_field = "date_start"
|
date_field = "date_start"
|
||||||
|
allow_empty = True # Do not 404 if no galleries
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
"""Hide galleries with only private photos"""
|
"""Hide galleries with only private photos"""
|
||||||
|
|
@ -36,6 +37,12 @@ class GalleryDateView(LoginRequiredMixin):
|
||||||
else:
|
else:
|
||||||
return qs.filter(photos__is_public=True).distinct()
|
return qs.filter(photos__is_public=True).distinct()
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
"""Always show all years in archive"""
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
context['date_list'] = self.get_queryset().dates(self.date_field, 'year', 'DESC')
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
class GalleryArchiveIndexView(GalleryDateView, ArchiveIndexView):
|
class GalleryArchiveIndexView(GalleryDateView, ArchiveIndexView):
|
||||||
pass
|
pass
|
||||||
|
|
@ -91,7 +98,7 @@ class PhotoReportView(LoginRequiredMixin, DetailView):
|
||||||
url = request.build_absolute_uri(url)
|
url = request.build_absolute_uri(url)
|
||||||
|
|
||||||
# Send mail to managers
|
# Send mail to managers
|
||||||
mail_managers(
|
mail_admins(
|
||||||
subject=f"Abuse report for photo id {photo.pk}",
|
subject=f"Abuse report for photo id {photo.pk}",
|
||||||
message=f"{self.request.user.username} reported an abuse for `{photo.title}`: {url}#lg=1&slide={photo.pk}",
|
message=f"{self.request.user.username} reported an abuse for `{photo.title}`: {url}#lg=1&slide={photo.pk}",
|
||||||
)
|
)
|
||||||
|
|
@ -182,10 +189,15 @@ class GalleryUpload(PermissionRequiredMixin, FormView):
|
||||||
# Upload photos
|
# Upload photos
|
||||||
# We take files from the request to support multiple upload
|
# We take files from the request to support multiple upload
|
||||||
files = self.request.FILES.getlist("file_field")
|
files = self.request.FILES.getlist("file_field")
|
||||||
|
|
||||||
|
# Get or create gallery
|
||||||
gallery = form.get_or_create_gallery()
|
gallery = form.get_or_create_gallery()
|
||||||
gallery_year = Path(str(gallery.date_start.year))
|
gallery_year = Path(str(gallery.date_start.year))
|
||||||
gallery_dir = gallery_year / gallery.slug
|
gallery_dir = gallery_year / gallery.slug
|
||||||
failed_upload = 0
|
|
||||||
|
# Upload pictures
|
||||||
|
uploaded_photo_name = []
|
||||||
|
already_exists = 0
|
||||||
for photo_file in files:
|
for photo_file in files:
|
||||||
# Check that we have a valid image
|
# Check that we have a valid image
|
||||||
try:
|
try:
|
||||||
|
|
@ -196,7 +208,6 @@ class GalleryUpload(PermissionRequiredMixin, FormView):
|
||||||
messages.error(
|
messages.error(
|
||||||
self.request, f"{photo_file.name} was not recognized as an image"
|
self.request, f"{photo_file.name} was not recognized as an image"
|
||||||
)
|
)
|
||||||
failed_upload += 1
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
title = f"{gallery.title} - {photo_file.name}"
|
title = f"{gallery.title} - {photo_file.name}"
|
||||||
|
|
@ -207,32 +218,32 @@ class GalleryUpload(PermissionRequiredMixin, FormView):
|
||||||
owner=self.request.user,
|
owner=self.request.user,
|
||||||
)
|
)
|
||||||
photo_name = str(gallery_dir / photo_file.name)
|
photo_name = str(gallery_dir / photo_file.name)
|
||||||
photo.image.save(photo_name, photo_file)
|
|
||||||
photo.save()
|
photo.save()
|
||||||
photo.galleries.set([gallery])
|
photo.galleries.set([gallery])
|
||||||
|
|
||||||
|
# Save to disk after successful database edit
|
||||||
|
photo.image.save(photo_name, photo_file)
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
messages.error(
|
already_exists += 1
|
||||||
self.request,
|
continue
|
||||||
f"{photo_file.name} was not uploaded. Maybe the photo was already uploaded.",
|
|
||||||
)
|
uploaded_photo_name.append(photo_file.name)
|
||||||
failed_upload += 1
|
|
||||||
|
|
||||||
# Notify user then managers
|
# Notify user then managers
|
||||||
if not failed_upload:
|
n_success = len(uploaded_photo_name)
|
||||||
messages.success(self.request, "All photos has been successfully uploaded.")
|
if already_exists:
|
||||||
|
messages.success(self.request, f"{n_success} photo(s) uploaded, {already_exists} photo(s) skipped as they already exist in this gallery.")
|
||||||
else:
|
else:
|
||||||
n_success = len(files) - failed_upload
|
messages.success(self.request, f"{n_success} photo(s) uploaded.")
|
||||||
messages.warning(
|
|
||||||
self.request, f"Only {n_success} photos were successfully uploaded !"
|
# Notify administrators on new uploads
|
||||||
|
gallery_url = reverse_lazy("photologue:pl-gallery", args=[gallery.slug])
|
||||||
|
gallery_url = self.request.build_absolute_uri(gallery_url)
|
||||||
|
if uploaded_photo_name:
|
||||||
|
photos = ", ".join(uploaded_photo_name)
|
||||||
|
mail_admins(
|
||||||
|
subject=f"New upload from {self.request.user.username}",
|
||||||
|
message=f"{self.request.user.username} has uploaded in <{gallery_url}>:\n{photos}",
|
||||||
)
|
)
|
||||||
|
|
||||||
gallery_title = form.cleaned_data["gallery"] or form.cleaned_data.get(
|
|
||||||
"new_gallery_title", ""
|
|
||||||
)
|
|
||||||
photos = ", ".join(f.name for f in files)
|
|
||||||
mail_managers(
|
|
||||||
subject="New photos upload",
|
|
||||||
message=f"{self.request.user.username} has uploaded in `{gallery_title}`: {photos}",
|
|
||||||
)
|
|
||||||
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue