X-Git-Url: https://git.mdrn.pl/audio.git/blobdiff_plain/bce69d0121eae093ea4be453c25f237b96700931..c175a7540d20336179dfd453183bfe69e6f5827e:/apps/archive/models.py diff --git a/apps/archive/models.py b/apps/archive/models.py index f9e86f6..4d3f838 100644 --- a/apps/archive/models.py +++ b/apps/archive/models.py @@ -1,10 +1,12 @@ # -*- coding: utf-8 -*- +import os.path from django.db import models from jsonfield.fields import JSONField from django.utils.translation import ugettext_lazy as _ from archive.constants import status -from archive.settings import FILES_PATH, ADVERT, LICENSE, ORGANIZATION, PROJECT +from archive.settings import FILES_SAVE_PATH, ADVERT, LICENSE, ORGANIZATION, PROJECT +from archive.utils import OverwriteStorage # Create your models here. @@ -24,8 +26,12 @@ class Project(models.Model): return self.name +def source_upload_to(intance, filename): + return os.path.join(FILES_SAVE_PATH, filename) # FIXME: what about really long file names? + + class Audiobook(models.Model): - source_file = models.FileField(upload_to='archive/files', max_length=255, + source_file = models.FileField(upload_to=source_upload_to, max_length=255, verbose_name=_('source file'), editable=False) source_sha1 = models.CharField(max_length=40, editable=False) @@ -43,14 +49,14 @@ class Audiobook(models.Model): mp3_status = models.SmallIntegerField(null=True, editable=False, choices=status.choices) mp3_task = models.CharField(max_length=64, null=True, editable=False) mp3_tags = JSONField(null=True, editable=False) - mp3_file = models.FileField(null=True, upload_to='archive/final', editable=False) + mp3_file = models.FileField(null=True, upload_to='archive/final', storage=OverwriteStorage(), editable=False) mp3_published_tags = JSONField(null=True, editable=False) mp3_published = models.DateTimeField(null=True, editable=False) ogg_status = models.SmallIntegerField(null=True, editable=False, choices=status.choices) ogg_task = models.CharField(max_length=64, null=True, editable=False) ogg_tags = JSONField(null=True, editable=False) - ogg_file = models.FileField(null=True, upload_to='archive/final', editable=False) + ogg_file = models.FileField(null=True, upload_to='archive/final', storage=OverwriteStorage(), editable=False) ogg_published_tags = JSONField(null=True, editable=False) ogg_published = models.DateTimeField(null=True, editable=False) @@ -94,4 +100,6 @@ class Audiobook(models.Model): 'organization': ORGANIZATION, 'title': title, 'flac_sha1': self.source_sha1, + 'project': self.project.name, + 'funded_by': self.project.sponsors, }