Fix upload paths for non-user related files

This commit is contained in:
Kumi 2021-06-14 09:50:35 +02:00
parent 517e35a7d0
commit 08e65b2150

View file

@ -18,7 +18,12 @@ def profile_to_coords(profile):
return name_to_coords("%s, %s, %s, %s" % (profile.street, profile.city, profile.zip, profile.country))
def upload_path(instance, filename):
return f'userfiles/{instance.user.id}/{uuid.uuid4()}/{filename}'
try:
user_id = instance.user.id
except:
user_id = "global"
return f'userfiles/{user_id}/{uuid.uuid4()}/{filename}'
def generate_token(length=6, characters=string.digits):
return "".join([SystemRandom().choice(characters) for _ in range(length)])