Retain filenames when cloning an event

This commit is contained in:
Christopher Banck
2022-09-13 10:46:08 +02:00
committed by GitHub
parent f2593d9b4b
commit f606747dc9

View File

@@ -69,6 +69,7 @@ from pretix.base.reldate import RelativeDateWrapper
from pretix.base.validators import EventSlugBanlistValidator from pretix.base.validators import EventSlugBanlistValidator
from pretix.helpers.database import GroupConcat from pretix.helpers.database import GroupConcat
from pretix.helpers.daterange import daterange from pretix.helpers.daterange import daterange
from pretix.helpers.hierarkey import clean_filename
from pretix.helpers.json import safe_string from pretix.helpers.json import safe_string
from pretix.helpers.thumb import get_thumbnail from pretix.helpers.thumb import get_thumbnail
@@ -917,11 +918,13 @@ class Event(EventMixin, LoggedModel):
s.object = self s.object = self
s.pk = None s.pk = None
if s.value.startswith('file://'): if s.value.startswith('file://'):
fi = default_storage.open(s.value[7:], 'rb') fi = default_storage.open(s.value[len('file://'):], 'rb')
nonce = get_random_string(length=8) nonce = get_random_string(length=8)
fname_base = clean_filename(os.path.basename(s.value))
# TODO: make sure pub is always correct # TODO: make sure pub is always correct
fname = 'pub/%s/%s/%s.%s.%s' % ( fname = 'pub/%s/%s/%s.%s.%s' % (
self.organizer.slug, self.slug, s.key, nonce, s.value.split('.')[-1] self.organizer.slug, self.slug, fname_base, nonce, s.value.split('.')[-1]
) )
newname = default_storage.save(fname, fi) newname = default_storage.save(fname, fi)
s.value = 'file://' + newname s.value = 'file://' + newname