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