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', max_length=255,
29 verbose_name=_('source file'), editable=False)
30 source_sha1 = models.CharField(max_length=40, editable=False)
32 title = models.CharField(max_length=255, verbose_name=_('title'))
33 artist = models.CharField(max_length=255, verbose_name=_('artist'))
34 conductor = models.CharField(max_length=255, verbose_name=_('conductor'))
35 encoded_by = models.CharField(max_length=255, verbose_name=_('encoded by'))
36 date = models.CharField(max_length=255, verbose_name=_('date'))
37 project = models.ForeignKey(Project, verbose_name=_('project'))
38 url = models.URLField(max_length=255, verbose_name=_('book url'))
39 translator = models.CharField(max_length=255, null=True, blank=True, verbose_name=_('translator'))
40 modified = models.DateTimeField(null=True, editable=False)
43 mp3_status = models.SmallIntegerField(null=True, editable=False, choices=status.choices)
44 mp3_task = models.CharField(max_length=64, null=True, editable=False)
45 mp3_tags = JSONField(null=True, editable=False)
46 mp3_file = models.FileField(null=True, upload_to='archive/final', editable=False)
47 mp3_published_tags = JSONField(null=True, editable=False)
48 mp3_published = models.DateTimeField(null=True, editable=False)
50 ogg_status = models.SmallIntegerField(null=True, editable=False, choices=status.choices)
51 ogg_task = models.CharField(max_length=64, null=True, editable=False)
52 ogg_tags = JSONField(null=True, editable=False)
53 ogg_file = models.FileField(null=True, upload_to='archive/final', editable=False)
54 ogg_published_tags = JSONField(null=True, editable=False)
55 ogg_published = models.DateTimeField(null=True, editable=False)
59 verbose_name = _("audiobook")
60 verbose_name_plural = _("audiobooks")
63 def __unicode__(self):
67 return self.mp3_published and self.ogg_published
69 def new_publish_tags(self):
72 title += u' (tłum. %s)' % self.translator
74 copyright = u"%s %s. Licensed to the public under %s verify at %s" % (
75 self.date, ORGANIZATION, LICENSE, self.url)
77 comment = u"Audiobook nagrany w ramach projektu %s%s.\n%s" % (
79 u" finansowanego przez %s" % self.project.sponsors if self.project.sponsors else "",
84 'albumartist': ORGANIZATION,
85 'artist': self.artist,
87 'conductor': self.conductor,
89 'copyright': copyright,
94 'organization': ORGANIZATION,
96 'flac_sha1': self.source_sha1,