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
class UploadForm(forms.Form):
file_field = forms.FileField(
label="",
widget=forms.FileInput(
class MultipleFileInput(forms.ClearableFileInput):
allow_multiple_selected = True
class MultipleFileField(forms.FileField):
def __init__(self, *args, **kwargs):
kwargs.setdefault(
"widget",
MultipleFileInput(
attrs={
"accept": "image/*",
"multiple": True,
"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.objects.all(),
label=_("Gallery"),

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -34,7 +34,7 @@ LATEST_LIMIT = getattr(settings, "PHOTOLOGUE_GALLERY_LATEST_LIMIT", None)
IMAGE_FIELD_MAX_LENGTH = getattr(settings, "PHOTOLOGUE_IMAGE_FIELD_MAX_LENGTH", 100)
# Modify image file buffer size.
ImageFile.MAXBLOCK = getattr(settings, "PHOTOLOGUE_MAXBLOCK", 256 * 2 ** 10)
ImageFile.MAXBLOCK = getattr(settings, "PHOTOLOGUE_MAXBLOCK", 256 * 2**10)
# Look for user function to define file paths
PHOTOLOGUE_PATH = getattr(settings, "PHOTOLOGUE_PATH", None)
@ -190,7 +190,7 @@ class Gallery(models.Model):
photo_set = self.photos.filter(is_public=True)
else:
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):
"""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):
"""Always show all years in archive"""
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
@ -186,10 +188,6 @@ class GalleryUpload(PermissionRequiredMixin, FormView):
permission_required = "photologue.add_gallery"
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
gallery = form.get_or_create_gallery()
gallery_year = Path(str(gallery.date_start.year))
@ -198,6 +196,7 @@ class GalleryUpload(PermissionRequiredMixin, FormView):
# Upload pictures
uploaded_photo_name = []
already_exists = 0
files = form.cleaned_data["file_field"]
for photo_file in files:
# Check that we have a valid image
try:
@ -232,7 +231,10 @@ class GalleryUpload(PermissionRequiredMixin, FormView):
# Notify user then managers
n_success = len(uploaded_photo_name)
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:
messages.success(self.request, f"{n_success} photo(s) uploaded.")