Merge branch 'fix_bookworm' into 'master'

Debian Bookworm compatibility

See merge request bde/photo21!29
This commit is contained in:
me5na7qbjqbrp 2023-08-05 13:46:20 +02:00
commit f6f59e8a63
10 changed files with 44 additions and 29 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -13,17 +13,34 @@ from django.utils.translation import gettext_lazy as _
from .models import Gallery, Tag from .models import Gallery, Tag
class UploadForm(forms.Form): class MultipleFileInput(forms.ClearableFileInput):
file_field = forms.FileField( allow_multiple_selected = True
label="",
widget=forms.FileInput(
class MultipleFileField(forms.FileField):
def __init__(self, *args, **kwargs):
kwargs.setdefault(
"widget",
MultipleFileInput(
attrs={ attrs={
"accept": "image/*", "accept": "image/*",
"multiple": True,
"class": "mb-3", "class": "mb-3",
} }
), ),
) )
super().__init__(*args, **kwargs)
def clean(self, data, initial=None):
single_file_clean = super().clean
if isinstance(data, (list, tuple)):
result = [single_file_clean(d, initial) for d in data]
else:
result = single_file_clean(data, initial)
return result
class UploadForm(forms.Form):
file_field = MultipleFileField(label="")
gallery = forms.ModelChoiceField( gallery = forms.ModelChoiceField(
Gallery.objects.all(), Gallery.objects.all(),
label=_("Gallery"), label=_("Gallery"),

View file

@ -53,7 +53,7 @@ class Command(BaseCommand):
# Delete them if --delete # Delete them if --delete
if options["delete"]: if options["delete"]:
self.stdout.write(" Deleting duplicate in {} :".format(gallery.slug)) self.stdout.write(" Deleting duplicate in {} :".format(gallery.slug))
for (_original, copies) in duplicates: for _original, copies in duplicates:
for copy in copies: for copy in copies:
self.stdout.write(" Deleting {}...".format(copy.slug)) self.stdout.write(" Deleting {}...".format(copy.slug))
copy.delete() copy.delete()

View file

@ -6,7 +6,6 @@ from photologue.models import ImageModel, PhotoSize
class Command(BaseCommand): class Command(BaseCommand):
help = "Manages Photologue cache file for the given sizes." help = "Manages Photologue cache file for the given sizes."
def add_arguments(self, parser): def add_arguments(self, parser):

View file

@ -12,7 +12,6 @@ import photologue.models
class Migration(migrations.Migration): class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [

View file

@ -6,7 +6,6 @@ from django.db import migrations
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
("photologue", "0001_initial"), ("photologue", "0001_initial"),
] ]

View file

@ -6,7 +6,6 @@ from django.db import migrations
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
("photologue", "0002_auto_20220130_1020"), ("photologue", "0002_auto_20220130_1020"),
] ]

View file

@ -190,7 +190,7 @@ class Gallery(models.Model):
photo_set = self.photos.filter(is_public=True) photo_set = self.photos.filter(is_public=True)
else: else:
photo_set = self.photos photo_set = self.photos
return random.sample(sorted(set(photo_set)), count) return random.sample(list(photo_set), count)
def photo_count(self, public=True): def photo_count(self, public=True):
"""Return a count of all the photos in this gallery.""" """Return a count of all the photos in this gallery."""

View file

@ -40,7 +40,9 @@ class GalleryDateView(LoginRequiredMixin):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
"""Always show all years in archive""" """Always show all years in archive"""
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['date_list'] = self.get_queryset().dates(self.date_field, 'year', 'DESC') context["date_list"] = self.get_queryset().dates(
self.date_field, "year", "DESC"
)
return context return context
@ -186,10 +188,6 @@ class GalleryUpload(PermissionRequiredMixin, FormView):
permission_required = "photologue.add_gallery" permission_required = "photologue.add_gallery"
def form_valid(self, form): def form_valid(self, form):
# Upload photos
# We take files from the request to support multiple upload
files = self.request.FILES.getlist("file_field")
# Get or create gallery # 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))
@ -198,6 +196,7 @@ class GalleryUpload(PermissionRequiredMixin, FormView):
# Upload pictures # Upload pictures
uploaded_photo_name = [] uploaded_photo_name = []
already_exists = 0 already_exists = 0
files = form.cleaned_data["file_field"]
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:
@ -232,7 +231,10 @@ class GalleryUpload(PermissionRequiredMixin, FormView):
# Notify user then managers # Notify user then managers
n_success = len(uploaded_photo_name) n_success = len(uploaded_photo_name)
if already_exists: 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.") messages.success(
self.request,
f"{n_success} photo(s) uploaded, {already_exists} photo(s) skipped as they already exist in this gallery.",
)
else: else:
messages.success(self.request, f"{n_success} photo(s) uploaded.") messages.success(self.request, f"{n_success} photo(s) uploaded.")