add file path generation func
This commit is contained in:
parent
009236990a
commit
1b0e6f24fe
6 changed files with 25 additions and 52 deletions
|
@ -5,19 +5,13 @@ from django.db import models
|
|||
from django.core.serializers.json import DjangoJSONEncoder
|
||||
from django.shortcuts import reverse
|
||||
from common.models import Entity, Mark, Review, Tag
|
||||
from common.utils import GenerateDateUUIDMediaFilePath
|
||||
from boofilsic.settings import BOOK_MEDIA_PATH_ROOT, DEFAULT_BOOK_IMAGE
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
def book_cover_path(instance, filename):
|
||||
ext = filename.split('.')[-1]
|
||||
filename = "%s.%s" % (uuid.uuid4(), ext)
|
||||
root = ''
|
||||
if BOOK_MEDIA_PATH_ROOT.endswith('/'):
|
||||
root = BOOK_MEDIA_PATH_ROOT
|
||||
else:
|
||||
root = BOOK_MEDIA_PATH_ROOT + '/'
|
||||
return root + timezone.now().strftime('%Y/%m/%d') + f'{filename}'
|
||||
return GenerateDateUUIDMediaFilePath(instance, filename, BOOK_MEDIA_PATH_ROOT)
|
||||
|
||||
|
||||
class Book(Entity):
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import uuid
|
||||
from django.utils import timezone
|
||||
|
||||
class PageLinksGenerator:
|
||||
# TODO inherit django paginator
|
||||
"""
|
||||
|
@ -62,4 +65,14 @@ def ChoicesDictGenerator(choices_enum):
|
|||
for attr in dir(choices_enum):
|
||||
if not '__' in attr:
|
||||
choices_dict[getattr(choices_enum, attr).value] = getattr(choices_enum, attr).label
|
||||
return choices_dict
|
||||
return choices_dict
|
||||
|
||||
def GenerateDateUUIDMediaFilePath(instance, filename, path_root):
|
||||
ext = filename.split('.')[-1]
|
||||
filename = "%s.%s" % (uuid.uuid4(), ext)
|
||||
root = ''
|
||||
if path_root.endswith('/'):
|
||||
root = path_root
|
||||
else:
|
||||
root = path_root + '/'
|
||||
return root + timezone.now().strftime('%Y/%m/%d') + f'{filename}'
|
||||
|
|
|
@ -5,20 +5,13 @@ from django.db import models
|
|||
from django.core.serializers.json import DjangoJSONEncoder
|
||||
from django.shortcuts import reverse
|
||||
from common.models import Entity, Mark, Review, Tag
|
||||
from common.utils import ChoicesDictGenerator
|
||||
from common.utils import ChoicesDictGenerator, GenerateDateUUIDMediaFilePath
|
||||
from boofilsic.settings import GAME_MEDIA_PATH_ROOT, DEFAULT_GAME_IMAGE
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
def game_cover_path(instance, filename):
|
||||
ext = filename.split('.')[-1]
|
||||
filename = "%s.%s" % (uuid.uuid4(), ext)
|
||||
root = ''
|
||||
if GAME_MEDIA_PATH_ROOT.endswith('/'):
|
||||
root = GAME_MEDIA_PATH_ROOT
|
||||
else:
|
||||
root = GAME_MEDIA_PATH_ROOT + '/'
|
||||
return root + timezone.now().strftime('%Y/%m/%d') + f'{filename}'
|
||||
return GenerateDateUUIDMediaFilePath(instance, filename, GAME_MEDIA_PATH_ROOT)
|
||||
|
||||
|
||||
class Game(Entity):
|
||||
|
|
|
@ -5,20 +5,13 @@ from django.db import models
|
|||
from django.core.serializers.json import DjangoJSONEncoder
|
||||
from django.shortcuts import reverse
|
||||
from common.models import Entity, Mark, Review, Tag
|
||||
from common.utils import ChoicesDictGenerator
|
||||
from common.utils import ChoicesDictGenerator, GenerateDateUUIDMediaFilePath
|
||||
from boofilsic.settings import MOVIE_MEDIA_PATH_ROOT, DEFAULT_MOVIE_IMAGE
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
def movie_cover_path(instance, filename):
|
||||
ext = filename.split('.')[-1]
|
||||
filename = "%s.%s" % (uuid.uuid4(), ext)
|
||||
root = ''
|
||||
if MOVIE_MEDIA_PATH_ROOT.endswith('/'):
|
||||
root = MOVIE_MEDIA_PATH_ROOT
|
||||
else:
|
||||
root = MOVIE_MEDIA_PATH_ROOT + '/'
|
||||
return root + timezone.now().strftime('%Y/%m/%d') + f'{filename}'
|
||||
return GenerateDateUUIDMediaFilePath(instance, filename, MOVIE_MEDIA_PATH_ROOT)
|
||||
|
||||
|
||||
class MovieGenreEnum(models.TextChoices):
|
||||
|
|
|
@ -5,31 +5,17 @@ from django.db import models
|
|||
from django.core.serializers.json import DjangoJSONEncoder
|
||||
from django.shortcuts import reverse
|
||||
from common.models import Entity, Mark, Review, Tag
|
||||
from common.utils import ChoicesDictGenerator
|
||||
from common.utils import ChoicesDictGenerator, GenerateDateUUIDMediaFilePath
|
||||
from boofilsic.settings import SONG_MEDIA_PATH_ROOT, DEFAULT_SONG_IMAGE, ALBUM_MEDIA_PATH_ROOT, DEFAULT_ALBUM_IMAGE
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
def song_cover_path(instance, filename):
|
||||
ext = filename.split('.')[-1]
|
||||
filename = "%s.%s" % (uuid.uuid4(), ext)
|
||||
root = ''
|
||||
if SONG_MEDIA_PATH_ROOT.endswith('/'):
|
||||
root = SONG_MEDIA_PATH_ROOT
|
||||
else:
|
||||
root = SONG_MEDIA_PATH_ROOT + '/'
|
||||
return root + timezone.now().strftime('%Y/%m/%d') + f'{filename}'
|
||||
return GenerateDateUUIDMediaFilePath(instance, filename, SONG_MEDIA_PATH_ROOT)
|
||||
|
||||
|
||||
def album_cover_path(instance, filename):
|
||||
ext = filename.split('.')[-1]
|
||||
filename = "%s.%s" % (uuid.uuid4(), ext)
|
||||
root = ''
|
||||
if ALBUM_MEDIA_PATH_ROOT.endswith('/'):
|
||||
root = ALBUM_MEDIA_PATH_ROOT
|
||||
else:
|
||||
root = ALBUM_MEDIA_PATH_ROOT + '/'
|
||||
return root + timezone.now().strftime('%Y/%m/%d') + f'{filename}'
|
||||
return GenerateDateUUIDMediaFilePath(instance, filename, ALBUM_MEDIA_PATH_ROOT)
|
||||
|
||||
|
||||
class Album(Entity):
|
||||
|
|
|
@ -6,17 +6,11 @@ from django.utils import timezone
|
|||
from boofilsic.settings import REPORT_MEDIA_PATH_ROOT, DEFAULT_PASSWORD
|
||||
from django.core.serializers.json import DjangoJSONEncoder
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from common.utils import GenerateDateUUIDMediaFilePath
|
||||
|
||||
|
||||
def report_image_path(instance, filename):
|
||||
ext = filename.split('.')[-1]
|
||||
filename = "%s.%s" % (uuid.uuid4(), ext)
|
||||
root = ''
|
||||
if REPORT_MEDIA_PATH_ROOT.endswith('/'):
|
||||
root = REPORT_MEDIA_PATH_ROOT
|
||||
else:
|
||||
root = REPORT_MEDIA_PATH_ROOT + '/'
|
||||
return root + timezone.now().strftime('%Y/%m/%d') + f'{filename}'
|
||||
return GenerateDateUUIDMediaFilePath(instance, filename, REPORT_MEDIA_PATH_ROOT)
|
||||
|
||||
|
||||
class User(AbstractUser):
|
||||
|
|
Loading…
Add table
Reference in a new issue