1 # -*- coding: utf-8 -*-
4 from django.db import models
5 from jsonfield.fields import JSONField
6 from django.utils.translation import ugettext_lazy as _
7 from archive.constants import status
8 from archive.settings import FILES_SAVE_PATH, ADVERT, LICENSE, ORGANIZATION, PROJECT
9 from archive.utils import OverwriteStorage
11 # Create your models here.
14 class Project(models.Model):
15 """ an audiobook project, needed for specyfing sponsors """
17 name = models.CharField(max_length=128, unique=True, db_index=True, verbose_name="Nazwa")
18 sponsors = models.TextField(blank=True, null=True, verbose_name="Sponsorzy")
21 verbose_name = _("project")
22 verbose_name_plural = _("projects")
25 def __unicode__(self):
29 def source_upload_to(intance, filename):
30 return os.path.join(FILES_SAVE_PATH, filename) # FIXME: what about really long file names?
33 class Audiobook(models.Model):
34 source_file = models.FileField(upload_to=source_upload_to, max_length=255,
35 verbose_name=_('source file'), editable=False)
36 source_sha1 = models.CharField(max_length=40, editable=False)
38 title = models.CharField(max_length=255, verbose_name=_('title'))
39 artist = models.CharField(max_length=255, verbose_name=_('artist'))
40 conductor = models.CharField(max_length=255, verbose_name=_('conductor'))
41 encoded_by = models.CharField(max_length=255, verbose_name=_('encoded by'))
42 date = models.CharField(max_length=255, verbose_name=_('date'))
43 project = models.ForeignKey(Project, verbose_name=_('project'))
44 url = models.URLField(max_length=255, verbose_name=_('book url'))
45 translator = models.CharField(max_length=255, null=True, blank=True, verbose_name=_('translator'))
46 modified = models.DateTimeField(null=True, editable=False)
49 mp3_status = models.SmallIntegerField(null=True, editable=False, choices=status.choices)
50 mp3_task = models.CharField(max_length=64, null=True, editable=False)
51 mp3_tags = JSONField(null=True, editable=False)
52 mp3_file = models.FileField(null=True, upload_to='archive/final', storage=OverwriteStorage(), editable=False)
53 mp3_published_tags = JSONField(null=True, editable=False)
54 mp3_published = models.DateTimeField(null=True, editable=False)
56 ogg_status = models.SmallIntegerField(null=True, editable=False, choices=status.choices)
57 ogg_task = models.CharField(max_length=64, null=True, editable=False)
58 ogg_tags = JSONField(null=True, editable=False)
59 ogg_file = models.FileField(null=True, upload_to='archive/final', storage=OverwriteStorage(), editable=False)
60 ogg_published_tags = JSONField(null=True, editable=False)
61 ogg_published = models.DateTimeField(null=True, editable=False)
65 verbose_name = _("audiobook")
66 verbose_name_plural = _("audiobooks")
69 def __unicode__(self):
73 return self.mp3_published and self.ogg_published
75 def new_publish_tags(self):
78 title += u' (tłum. %s)' % self.translator
80 copyright = u"%s %s. Licensed to the public under %s verify at %s" % (
81 self.date, ORGANIZATION, LICENSE, self.url)
83 comment = u"Audiobook nagrany w ramach projektu %s%s.\n%s" % (
85 u" finansowanego przez %s" % self.project.sponsors if self.project.sponsors else "",
90 'albumartist': ORGANIZATION,
91 'artist': self.artist,
93 'conductor': self.conductor,
95 'copyright': copyright,
100 'organization': ORGANIZATION,
102 'flac_sha1': self.source_sha1,
103 'project': self.project.name,
104 'funded_by': self.project.sponsors,