1 # -*- coding: utf-8 -*-
3 from django.db import models
4 from jsonfield.fields import JSONField
5 from django.utils.translation import ugettext_lazy as _
6 from archive.constants import status
7 from archive.settings import FILES_PATH, ADVERT, LICENSE, ORGANIZATION, PROJECT
8 from archive.utils import OverwriteStorage
10 # Create your models here.
13 class Project(models.Model):
14 """ an audiobook project, needed for specyfing sponsors """
16 name = models.CharField(max_length=128, unique=True, db_index=True, verbose_name="Nazwa")
17 sponsors = models.TextField(blank=True, null=True, verbose_name="Sponsorzy")
20 verbose_name = _("project")
21 verbose_name_plural = _("projects")
24 def __unicode__(self):
28 class Audiobook(models.Model):
29 source_file = models.FileField(upload_to='archive/files', max_length=255,
30 verbose_name=_('source file'), editable=False)
31 source_sha1 = models.CharField(max_length=40, editable=False)
33 title = models.CharField(max_length=255, verbose_name=_('title'))
34 artist = models.CharField(max_length=255, verbose_name=_('artist'))
35 conductor = models.CharField(max_length=255, verbose_name=_('conductor'))
36 encoded_by = models.CharField(max_length=255, verbose_name=_('encoded by'))
37 date = models.CharField(max_length=255, verbose_name=_('date'))
38 project = models.ForeignKey(Project, verbose_name=_('project'))
39 url = models.URLField(max_length=255, verbose_name=_('book url'))
40 translator = models.CharField(max_length=255, null=True, blank=True, verbose_name=_('translator'))
41 modified = models.DateTimeField(null=True, editable=False)
44 mp3_status = models.SmallIntegerField(null=True, editable=False, choices=status.choices)
45 mp3_task = models.CharField(max_length=64, null=True, editable=False)
46 mp3_tags = JSONField(null=True, editable=False)
47 mp3_file = models.FileField(null=True, upload_to='archive/final', storage=OverwriteStorage(), editable=False)
48 mp3_published_tags = JSONField(null=True, editable=False)
49 mp3_published = models.DateTimeField(null=True, editable=False)
51 ogg_status = models.SmallIntegerField(null=True, editable=False, choices=status.choices)
52 ogg_task = models.CharField(max_length=64, null=True, editable=False)
53 ogg_tags = JSONField(null=True, editable=False)
54 ogg_file = models.FileField(null=True, upload_to='archive/final', storage=OverwriteStorage(), editable=False)
55 ogg_published_tags = JSONField(null=True, editable=False)
56 ogg_published = models.DateTimeField(null=True, editable=False)
60 verbose_name = _("audiobook")
61 verbose_name_plural = _("audiobooks")
64 def __unicode__(self):
68 return self.mp3_published and self.ogg_published
70 def new_publish_tags(self):
73 title += u' (tłum. %s)' % self.translator
75 copyright = u"%s %s. Licensed to the public under %s verify at %s" % (
76 self.date, ORGANIZATION, LICENSE, self.url)
78 comment = u"Audiobook nagrany w ramach projektu %s%s.\n%s" % (
80 u" finansowanego przez %s" % self.project.sponsors if self.project.sponsors else "",
85 'albumartist': ORGANIZATION,
86 'artist': self.artist,
88 'conductor': self.conductor,
90 'copyright': copyright,
95 'organization': ORGANIZATION,
97 'flac_sha1': self.source_sha1,
98 'project': self.project.name,
99 'funded_by': self.project.sponsors,