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
9 # Create your models here.
12 class Project(models.Model):
13 """ an audiobook project, needed for specyfing sponsors """
15 name = models.CharField(max_length=128, unique=True, db_index=True, verbose_name="Nazwa")
16 sponsors = models.TextField(blank=True, null=True, verbose_name="Sponsorzy")
19 verbose_name = _("project")
20 verbose_name_plural = _("projects")
23 def __unicode__(self):
27 class Audiobook(models.Model):
28 source_file = models.FileField(upload_to='archive/files', verbose_name=_('source file'), editable=False)
29 source_sha1 = models.CharField(max_length=40, editable=False)
31 title = models.CharField(max_length=255, verbose_name=_('title'))
32 artist = models.CharField(max_length=255, verbose_name=_('artist'))
33 conductor = models.CharField(max_length=255, verbose_name=_('conductor'))
34 encoded_by = models.CharField(max_length=255, verbose_name=_('encoded by'))
35 date = models.CharField(max_length=255, verbose_name=_('date'))
36 project = models.ForeignKey(Project, verbose_name=_('project'))
37 url = models.URLField(max_length=255, verbose_name=_('book url'))
38 translator = models.CharField(max_length=255, null=True, blank=True, verbose_name=_('translator'))
39 modified = models.DateTimeField(null=True, editable=False)
42 mp3_status = models.SmallIntegerField(null=True, editable=False, choices=status.choices)
43 mp3_task = models.CharField(max_length=64, null=True, editable=False)
44 mp3_tags = JSONField(null=True, editable=False)
45 mp3_file = models.FileField(null=True, upload_to='archive/final', editable=False)
46 mp3_published_tags = JSONField(null=True, editable=False)
47 mp3_published = models.DateTimeField(null=True, editable=False)
49 ogg_status = models.SmallIntegerField(null=True, editable=False, choices=status.choices)
50 ogg_task = models.CharField(max_length=64, null=True, editable=False)
51 ogg_tags = JSONField(null=True, editable=False)
52 ogg_file = models.FileField(null=True, upload_to='archive/final', editable=False)
53 ogg_published_tags = JSONField(null=True, editable=False)
54 ogg_published = models.DateTimeField(null=True, editable=False)
58 verbose_name = _("audiobook")
59 verbose_name_plural = _("audiobooks")
62 def __unicode__(self):
66 return self.mp3_published and self.ogg_published
68 def new_publish_tags(self):
71 title += u' (tłum. %s)' % self.translator
73 copyright = u"%s %s. Licensed to the public under %s verify at %s" % (
74 self.date, ORGANIZATION, LICENSE, self.url)
76 comment = u"Audiobook nagrany w ramach projektu %s%s.\n%s" % (
78 u" finansowanego przez %s" % self.project.sponsors if self.project.sponsors else "",
83 'albumartist': ORGANIZATION,
84 'artist': self.artist,
86 'conductor': self.conductor,
88 'copyright': copyright,
93 'organization': ORGANIZATION,
95 'flac_sha1': self.source_sha1,