Changeset View
Changeset View
Standalone View
Standalone View
common/upload_paths.py
| import hashlib | import hashlib | ||||
| import typing | import typing | ||||
| import uuid | import uuid | ||||
| from pathlib import Path | from pathlib import Path | ||||
| if typing.TYPE_CHECKING: | if typing.TYPE_CHECKING: | ||||
| import assets.models.StaticAsset | import static_assets.models.StaticAsset | ||||
| import films | import films | ||||
| import training | import training | ||||
| def generate_hash_from_filename(filename: str) -> str: | def generate_hash_from_filename(filename: str) -> str: | ||||
| """Combine filename and uuid4 and get a unique string.""" | """Combine filename and uuid4 and get a unique string.""" | ||||
| unique_filename = f'{uuid.uuid4()}_{filename}' | unique_filename = f'{uuid.uuid4()}_{filename}' | ||||
| return hashlib.md5(unique_filename.encode('utf-8')).hexdigest() | return hashlib.md5(unique_filename.encode('utf-8')).hexdigest() | ||||
| ModelWithFile = typing.Union[ | ModelWithFile = typing.Union[ | ||||
| 'assets.models.StaticAsset', | 'static_assets.models.StaticAsset', | ||||
| 'films.models.Film', | 'films.models.Film', | ||||
| 'films.models.Collection', | 'films.models.Collection', | ||||
| 'training.models.Training', | 'training.models.Training', | ||||
| 'training.models.Video', | 'training.models.Video', | ||||
| 'training.models.Asset', | 'training.models.Asset', | ||||
| ] | ] | ||||
| Show All 13 Lines | |||||