Skip to content
Snippets Groups Projects
Verified Commit 6da05900 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Remove instance-based renaming from path_and_rename

parent 7ed1f6f8
1 merge request!125Move path_and_rename to core_helpers.py and delete old helper.py
Pipeline #673 failed
......@@ -125,14 +125,13 @@ def celery_optional(orig: Callable) -> Callable:
return orig
def path_and_rename(instance, filename):
upload_to = 'files'
ext = filename.split('.')[-1].lower()
# get filename
if instance.pk:
filename = '{}.{}'.format(instance.pk, ext)
else:
# set filename as random string
filename = '{}.{}'.format(uuid4().hex, ext)
def path_and_rename(instance, filename: str, upload_to: str = "files") -> str:
""" Updates path of an uploaded file while using in Django FileField """
_, ext = os.path.splitext(filename)
# set filename as random string
new_filename = '{}.{}'.format(uuid4().hex, ext)
# return the whole path to the file
return os.path.join(upload_to, filename)
return os.path.join(upload_to, new_filename)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment