Merge branch 'fix_bookworm' into 'master'
Debian Bookworm compatibility See merge request bde/photo21!29
This commit is contained in:
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
|
|
@ -13,17 +13,34 @@ from django.utils.translation import gettext_lazy as _
|
||||||
from .models import Gallery, Tag
|
from .models import Gallery, Tag
|
||||||
|
|
||||||
|
|
||||||
|
class MultipleFileInput(forms.ClearableFileInput):
|
||||||
|
allow_multiple_selected = True
|
||||||
|
|
||||||
|
|
||||||
|
class MultipleFileField(forms.FileField):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
kwargs.setdefault(
|
||||||
|
"widget",
|
||||||
|
MultipleFileInput(
|
||||||
|
attrs={
|
||||||
|
"accept": "image/*",
|
||||||
|
"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):
|
class UploadForm(forms.Form):
|
||||||
file_field = forms.FileField(
|
file_field = MultipleFileField(label="")
|
||||||
label="",
|
|
||||||
widget=forms.FileInput(
|
|
||||||
attrs={
|
|
||||||
"accept": "image/*",
|
|
||||||
"multiple": True,
|
|
||||||
"class": "mb-3",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
)
|
|
||||||
gallery = forms.ModelChoiceField(
|
gallery = forms.ModelChoiceField(
|
||||||
Gallery.objects.all(),
|
Gallery.objects.all(),
|
||||||
label=_("Gallery"),
|
label=_("Gallery"),
|
||||||
|
|
|
||||||
|
|
@ -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()
|
||||||
|
|
|
||||||
|
|
@ -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):
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ import photologue.models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
initial = True
|
initial = True
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|
|
||||||
|
|
@ -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"),
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -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"),
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -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)
|
IMAGE_FIELD_MAX_LENGTH = getattr(settings, "PHOTOLOGUE_IMAGE_FIELD_MAX_LENGTH", 100)
|
||||||
|
|
||||||
# Modify image file buffer size.
|
# 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
|
# Look for user function to define file paths
|
||||||
PHOTOLOGUE_PATH = getattr(settings, "PHOTOLOGUE_PATH", None)
|
PHOTOLOGUE_PATH = getattr(settings, "PHOTOLOGUE_PATH", None)
|
||||||
|
|
@ -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."""
|
||||||
|
|
|
||||||
|
|
@ -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.")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue