78c5ab36713f0f660de5944a012ad85778ffeda2
[audio.git] / apps / archive / models.py
1 from django.db import models
2 from jsonfield.fields import JSONField
3 from django.utils.translation import ugettext_lazy as _
4 from archive.settings import FILES_PATH
5
6 # Create your models here.
7
8
9 class Project(models.Model):
10     """ an audiobook project, needed for specyfing sponsors """
11
12     name = models.CharField(max_length=128, unique=True, db_index=True, verbose_name="Nazwa")
13     sponsors = models.TextField(blank=True, null=True, verbose_name="Sponsorzy")
14
15     class Meta:
16         verbose_name = _("project")
17         verbose_name_plural = _("projects")
18         ordering = ("name",)
19
20     def __unicode__(self):
21         return self.name
22
23
24 class Audiobook(models.Model):
25     source_file = models.FileField(upload_to=FILES_PATH, verbose_name=_('source file'), editable=False)
26
27     title = models.CharField(max_length=255, verbose_name=_('title'))
28     artist = models.CharField(max_length=255, verbose_name=_('artist'))
29     conductor = models.CharField(max_length=255, verbose_name=_('conductor'))
30     encoded_by = models.CharField(max_length=255, verbose_name=_('encoded by'))
31     date = models.CharField(max_length=255, verbose_name=_('date'))
32     project = models.ForeignKey(Project, verbose_name=_('project'))
33     url = models.URLField(max_length=255, verbose_name=_('book url'))
34     modified = models.DateTimeField(null=True, editable=False)
35
36     published_tags = JSONField(null=True, editable=False)
37     mp3_file = models.FileField(null=True, upload_to='archive/final', editable=False)
38     ogg_file = models.FileField(null=True, upload_to='archive/final', editable=False)
39     publishing_tags = JSONField(null=True, editable=False)
40
41     publish_wait = models.DateTimeField(null=True, editable=False) # somebody hit "publish"
42     publishing = models.BooleanField(default=False, editable=False)
43     published = models.DateTimeField(null=True, editable=False)
44
45     class Meta:
46         verbose_name = _("audiobook")
47         verbose_name_plural = _("audiobooks")
48         ordering = ("title",)
49
50     def __unicode__(self):
51         return self.title
52
53     def new_publish_tags(self):
54         return {
55             'title': self.title,
56             'copyright': 'Fundacja Nowoczesna Polska',
57         }