models.py 2.11 KB
Newer Older
fred's avatar
fred committed
1
from django.core.urlresolvers import reverse
2 3 4
from django.db import models
from django.utils.translation import ugettext_lazy as _

fred's avatar
fred committed
5 6
REMOTE_BASE_PATH = '/srv/soma/nonstop/'

7

fred's avatar
fred committed
8 9 10
class Artist(models.Model):
    name = models.CharField(_('Name'), max_length=255)

fred's avatar
fred committed
11 12 13
    class Meta:
        ordering = ['name']

fred's avatar
fred committed
14 15 16 17
    def get_absolute_url(self):
        return reverse('artist-view', kwargs={'pk': self.id})

    def recent_diffusions(self):
18 19
        return SomaLogLine.objects.filter(filepath__track__artist=self
                ).exclude(on_air=False).order_by('-play_timestamp')
fred's avatar
fred committed
20

fred's avatar
fred committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

class Album(models.Model):
    name = models.CharField(_('Name'), max_length=255)


LANGUAGES = [
    ('en', _('English')),
    ('fr', _('French')),
    ('nl', _('Dutch'))
]

class Track(models.Model):
    title = models.CharField(_('Title'), max_length=255)
    artist = models.ForeignKey(Artist, null=True)
    album = models.ForeignKey(Album, null=True)
    instru = models.BooleanField(_('Instru'), default=False)
    language = models.CharField(max_length=3,
            choices=LANGUAGES, blank=True)
    sabam = models.BooleanField('SABAM', default=True)
fred's avatar
fred committed
40
    cfwb = models.BooleanField('CFWB', default=False)
41
    nonstop_zones = models.ManyToManyField('emissions.Nonstop', null=True, blank=True)
fred's avatar
fred committed
42

fred's avatar
fred committed
43 44 45
    def get_absolute_url(self):
        return reverse('track-view', kwargs={'pk': self.id})

fred's avatar
fred committed
46
    def recent_diffusions(self):
47 48
        return SomaLogLine.objects.filter(filepath__track=self
                ).exclude(on_air=False).order_by('-play_timestamp')
fred's avatar
fred committed
49

fred's avatar
fred committed
50

51 52 53
class NonstopFile(models.Model):
    filepath = models.CharField(_('Filepath'), max_length=255)
    creation_timestamp = models.DateTimeField(auto_now_add=True, null=True)
fred's avatar
fred committed
54
    track = models.ForeignKey(Track, null=True)
55

fred's avatar
fred committed
56 57 58 59
    @property
    def short(self):
        return self.filepath[len(REMOTE_BASE_PATH):]

60

61 62 63 64 65 66
class SomaLogLine(models.Model):
    class Meta:
        verbose_name = _('Soma log line')
        verbose_name_plural = _('Soma log lines')
        ordering = ['play_timestamp']

67
    filepath = models.ForeignKey(NonstopFile)
68
    play_timestamp = models.DateTimeField()
fred's avatar
fred committed
69
    on_air = models.NullBooleanField('On Air')