Add video support with unified media display.
All checks were successful
Docker / build (release) Successful in 9s

This commit is contained in:
krek0 2026-05-16 15:13:14 +02:00
parent a634cc88bd
commit f4052a3d99
16 changed files with 700 additions and 224 deletions

View file

@ -19,20 +19,12 @@ class MultipleFileInput(forms.ClearableFileInput):
class MultipleFileField(forms.FileField):
allowed_extensions = [
"jpg",
"jpeg",
"png",
"gif",
"tiff",
] # Specify allowed extensions here
def __init__(self, *args, **kwargs):
kwargs.setdefault(
"widget",
MultipleFileInput(
attrs={
"accept": "image/*",
"accept": "image/*,video/*",
"class": "mb-3",
}
),
@ -41,25 +33,9 @@ class MultipleFileField(forms.FileField):
def clean(self, data, initial=None):
single_file_clean = super().clean
if isinstance(data, (list, tuple)):
result = [self.validate_file(d, single_file_clean, initial) for d in data]
else:
result = self.validate_file(data, single_file_clean, initial)
return result
def validate_file(self, file, single_file_clean, initial):
# Perform the default clean
cleaned_file = single_file_clean(file, initial)
# Check the file extension
extension = file.name.split(".")[-1].lower()
if extension not in self.allowed_extensions:
raise forms.ValidationError(
f"{file.name} has an invalid file extension. "
f"Allowed extensions are: {', '.join(self.allowed_extensions)}"
)
return cleaned_file
return [single_file_clean(d, initial) for d in data]
return single_file_clean(data, initial)
class UploadForm(forms.Form):