forked from CGM_Public/pretix_original
Don't double file extension in clean_filename (#3942)
* Don't double file extension in clean_filename * Don't use display_name as ClearableBasenameFileInput.FakeFile.name Reason: it's used as the thumbnail source and therefore needs to be a valid file name and not some display name
This commit is contained in:
@@ -123,8 +123,6 @@ class ClearableBasenameFileInput(forms.ClearableFileInput):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
if hasattr(self.file, 'display_name'):
|
||||
return self.file.display_name
|
||||
return self.file.name
|
||||
|
||||
@property
|
||||
|
||||
@@ -32,9 +32,14 @@ def clean_filename(fname):
|
||||
|
||||
"Terms.pdf" → "Terms.pdf.OybgvyAH.22c0583727d5bc.pdf"
|
||||
|
||||
This function reverses this operation:
|
||||
This function reverses this operation (leaving names without doubled extension as-is):
|
||||
|
||||
"Terms.pdf.OybgvyAH.22c0583727d5bc.pdf" → "Terms.pdf"
|
||||
"Terms.pdf" → "Terms.pdf"
|
||||
"""
|
||||
ext = '.' + fname.split('.')[-1]
|
||||
return fname.rsplit(ext + ".", 1)[0] + ext
|
||||
parts = fname.rsplit(ext + ".", 1)
|
||||
if len(parts) == 1:
|
||||
return parts[0]
|
||||
else:
|
||||
return parts[0] + ext
|
||||
|
||||
Reference in New Issue
Block a user