X-Git-Url: https://git.mdrn.pl/audio.git/blobdiff_plain/d64f05ea901ccb7e61eacd9a5579bb81138b193d..e927d217b3ad62c17b43c34ca5838c61fc1928e8:/apps/archive/models.py?ds=inline diff --git a/apps/archive/models.py b/apps/archive/models.py index cf3829b..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,13 @@ 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', verbose_name=_('source file'), editable=False) + 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) title = models.CharField(max_length=255, verbose_name=_('title')) @@ -42,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) @@ -93,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, }