mirror of
https://github.com/pretix/pretix.git
synced 2026-05-09 15:54:03 +00:00
Only validate size on uploaded files
This commit is contained in:
@@ -5,6 +5,7 @@ from django import forms
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.core.files import File
|
from django.core.files import File
|
||||||
|
from django.core.files.uploadedfile import UploadedFile
|
||||||
from django.forms.utils import from_current_timezone
|
from django.forms.utils import from_current_timezone
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
@@ -110,7 +111,7 @@ class SizeFileField(forms.FileField):
|
|||||||
|
|
||||||
def clean(self, *args, **kwargs):
|
def clean(self, *args, **kwargs):
|
||||||
data = super().clean(*args, **kwargs)
|
data = super().clean(*args, **kwargs)
|
||||||
if data and self.max_size and data.size > self.max_size:
|
if isinstance(data, UploadedFile) and self.max_size and data.size > self.max_size:
|
||||||
raise forms.ValidationError(_("Please do not upload files larger than {size}!").format(
|
raise forms.ValidationError(_("Please do not upload files larger than {size}!").format(
|
||||||
SizeFileField._sizeof_fmt(self.max_size)
|
SizeFileField._sizeof_fmt(self.max_size)
|
||||||
))
|
))
|
||||||
|
|||||||
Reference in New Issue
Block a user