forked from CGM_Public/pretix_original
Compare commits
6 Commits
raphaelm-p
...
v2023.8.1.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4013d71b3c | ||
|
|
04c75557ff | ||
|
|
33fa62d6ac | ||
|
|
b6e27c8854 | ||
|
|
f23ea6386e | ||
|
|
4ddd3acae9 |
@@ -59,7 +59,7 @@ dependencies = [
|
|||||||
"dnspython==2.3.*",
|
"dnspython==2.3.*",
|
||||||
"drf_ujson2==1.7.*",
|
"drf_ujson2==1.7.*",
|
||||||
"geoip2==4.*",
|
"geoip2==4.*",
|
||||||
"importlib_metadata==6.*", # Polyfill, we can probably drop this once we require Python 3.10+
|
"importlib_metadata==7.*", # Polyfill, we can probably drop this once we require Python 3.10+
|
||||||
"isoweek",
|
"isoweek",
|
||||||
"jsonschema",
|
"jsonschema",
|
||||||
"kombu==5.3.*",
|
"kombu==5.3.*",
|
||||||
|
|||||||
@@ -19,4 +19,4 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License along with this program. If not, see
|
# You should have received a copy of the GNU Affero General Public License along with this program. If not, see
|
||||||
# <https://www.gnu.org/licenses/>.
|
# <https://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
__version__ = "2023.8.0"
|
__version__ = "2023.8.1"
|
||||||
|
|||||||
@@ -219,15 +219,17 @@ class ExtValidationMixin:
|
|||||||
|
|
||||||
def clean(self, *args, **kwargs):
|
def clean(self, *args, **kwargs):
|
||||||
data = super().clean(*args, **kwargs)
|
data = super().clean(*args, **kwargs)
|
||||||
if isinstance(data, UploadedFile):
|
|
||||||
filename = data.name
|
from ...base.models import CachedFile
|
||||||
|
if isinstance(data, (UploadedFile, CachedFile)):
|
||||||
|
filename = data.name if isinstance(data, UploadedFile) else data.filename
|
||||||
ext = os.path.splitext(filename)[1]
|
ext = os.path.splitext(filename)[1]
|
||||||
ext = ext.lower()
|
ext = ext.lower()
|
||||||
if ext not in self.ext_whitelist:
|
if ext not in self.ext_whitelist:
|
||||||
raise forms.ValidationError(_("Filetype not allowed!"))
|
raise forms.ValidationError(_("Filetype not allowed!"))
|
||||||
|
|
||||||
if ext in IMAGE_EXTS:
|
if ext in IMAGE_EXTS:
|
||||||
validate_uploaded_file_for_valid_image(data)
|
validate_uploaded_file_for_valid_image(data if isinstance(data, UploadedFile) else data.file)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@@ -257,6 +259,12 @@ class CachedFileField(ExtFileField):
|
|||||||
if isinstance(data, File):
|
if isinstance(data, File):
|
||||||
if hasattr(data, '_uploaded_to'):
|
if hasattr(data, '_uploaded_to'):
|
||||||
return data._uploaded_to
|
return data._uploaded_to
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.clean(data)
|
||||||
|
except ValidationError:
|
||||||
|
return None
|
||||||
|
|
||||||
cf = CachedFile.objects.create(
|
cf = CachedFile.objects.create(
|
||||||
expires=now() + datetime.timedelta(days=1),
|
expires=now() + datetime.timedelta(days=1),
|
||||||
date=now(),
|
date=now(),
|
||||||
@@ -268,6 +276,9 @@ class CachedFileField(ExtFileField):
|
|||||||
cf.save()
|
cf.save()
|
||||||
data._uploaded_to = cf
|
data._uploaded_to = cf
|
||||||
return cf
|
return cf
|
||||||
|
if isinstance(data, CachedFile):
|
||||||
|
return data
|
||||||
|
|
||||||
return super().bound_data(data, initial)
|
return super().bound_data(data, initial)
|
||||||
|
|
||||||
def clean(self, *args, **kwargs):
|
def clean(self, *args, **kwargs):
|
||||||
|
|||||||
@@ -44,11 +44,12 @@ def validate_uploaded_file_for_valid_image(f):
|
|||||||
# have to read the data into memory.
|
# have to read the data into memory.
|
||||||
if hasattr(f, 'temporary_file_path'):
|
if hasattr(f, 'temporary_file_path'):
|
||||||
file = f.temporary_file_path()
|
file = f.temporary_file_path()
|
||||||
|
elif hasattr(f, 'read'):
|
||||||
|
if hasattr(f, 'seek') and callable(f.seek):
|
||||||
|
f.seek(0)
|
||||||
|
file = BytesIO(f.read())
|
||||||
else:
|
else:
|
||||||
if hasattr(f, 'read'):
|
file = BytesIO(f['content'])
|
||||||
file = BytesIO(f.read())
|
|
||||||
else:
|
|
||||||
file = BytesIO(f['content'])
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user