diff options
Diffstat (limited to 'program')
-rw-r--r-- | program/__init__.py | 0 | ||||
-rw-r--r-- | program/admin.py | 56 | ||||
-rw-r--r-- | program/fixtures/broadcastformats.yaml | 35 | ||||
-rw-r--r-- | program/fixtures/musicfocus.yaml | 60 | ||||
-rw-r--r-- | program/fixtures/rrules.yaml | 25 | ||||
-rw-r--r-- | program/fixtures/showinformation.yaml | 48 | ||||
-rw-r--r-- | program/fixtures/showtopics.yaml | 30 | ||||
-rw-r--r-- | program/management/__init__.py | 2 | ||||
-rw-r--r-- | program/management/commands/__init__.py | 2 | ||||
-rw-r--r-- | program/models.py | 242 | ||||
-rw-r--r-- | program/tests.py | 0 | ||||
-rw-r--r-- | program/urls.py | 14 | ||||
-rw-r--r-- | program/views.py | 17 |
13 files changed, 531 insertions, 0 deletions
diff --git a/program/__init__.py b/program/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/program/__init__.py diff --git a/program/admin.py b/program/admin.py new file mode 100644 index 0000000..642beaf --- /dev/null +++ b/program/admin.py @@ -0,0 +1,56 @@ +from django.contrib import admin + +from models import BroadcastFormat, MusicFocus, ShowInformation, ShowTopic, Host, Note, ProgramSlot, Show, TimeSlot + +class BroadcastFormatAdmin(admin.ModelAdmin): + list_display = ('format',) + prepopulated_fields = {'slug': ('format',)} + +class MusicFocusAdmin(admin.ModelAdmin): + list_display = ('focus', 'abbrev') + prepopulated_fields = {'slug': ('focus',)} + +class ShowInformationAdmin(admin.ModelAdmin): + list_display = ('information', 'abbrev') + prepopulated_fields = {'slug': ('information',)} + +class ShowTopicAdmin(admin.ModelAdmin): + list_display = ('topic', 'abbrev') + prepopulated_fields = {'slug': ('topic',)} + +class NoteAdmin(admin.ModelAdmin): + list_filter = ('status',) + ordering = ('time_slot',) + +class TimeSlotInline(admin.TabularInline): + model = TimeSlot + +class ProgramSlotAdmin(admin.ModelAdmin): + date_hierarchy = 'dstart' + inlines = (TimeSlotInline,) + list_display = ('show', 'byweekday', 'rrule', 'tstart', 'tend', 'dstart', 'until') + list_filter = ('byweekday', 'rrule', 'is_repetition') + ordering = ('byweekday', 'dstart') + search_fields = ('show__name',) + +class ProgramSlotInline(admin.TabularInline): + model = ProgramSlot + +class ShowAdmin(admin.ModelAdmin): + filter_horizontal = ('hosts', 'owners', 'music_focus', 'show_information', 'show_topic') + inlines = (ProgramSlotInline,) + list_display = ('name', 'short_description', 'broadcast_format') + list_filter = ('broadcast_format', 'show_information', 'show_topic', 'music_focus',) + ordering = ('slug',) + prepopulated_fields = {'slug': ('name',)} + search_fields = ('name', 'short_description', 'description') + +admin.site.register(BroadcastFormat, BroadcastFormatAdmin) +admin.site.register(MusicFocus, MusicFocusAdmin) +admin.site.register(ShowInformation, ShowInformationAdmin) +admin.site.register(ShowTopic, ShowTopicAdmin) +admin.site.register(Note, NoteAdmin) +admin.site.register(ProgramSlot, ProgramSlotAdmin) +admin.site.register(Show, ShowAdmin) + +admin.site.register(Host)
\ No newline at end of file diff --git a/program/fixtures/broadcastformats.yaml b/program/fixtures/broadcastformats.yaml new file mode 100644 index 0000000..b6827aa --- /dev/null +++ b/program/fixtures/broadcastformats.yaml @@ -0,0 +1,35 @@ +- model: program.broadcastformat + pk: + fields: + format: Talk + slug: talk +- model: program.broadcastformat + pk: + fields: + format: Musiksendung + slug: musiksendung +- model: program.broadcastformat + pk: + fields: + format: Unmoderiertes Musikprogramm + slug: unmoderiertes-musikprogramm +- model: program.broadcastformat + pk: + fields: + format: Feature/Magazin + slug: feature-magazin +- model: program.broadcastformat + pk: + fields: + format: Experimentell + slug: experimentell +- model: program.broadcastformat + pk: + fields: + format: Hörspiel/Literatur + slug: horspiel-literatur +- model: program.broadcastformat + pk: + fields: + format: Vortrag/Diskussion + slug: vortrag-diskussion
\ No newline at end of file diff --git a/program/fixtures/musicfocus.yaml b/program/fixtures/musicfocus.yaml new file mode 100644 index 0000000..72a9dd9 --- /dev/null +++ b/program/fixtures/musicfocus.yaml @@ -0,0 +1,60 @@ +- model: program.musicfocus + pk: + fields: + focus: Jazz + abbrev: J + slug: jazz +- model: program.musicfocus + pk: + fields: + focus: Volksmusik/Folk + abbrev: V + slug: volksmusik-folk +- model: program.musicfocus + pk: + fields: + focus: Experimentelle Musik + abbrev: Ex + slug: expermentelle-musik +- model: program.musicfocus + pk: + fields: + focus: Rock/Indie + abbrev: R + slug: rock-indie +- model: program.musicfocus + pk: + fields: + focus: Metal/Hardrock + abbrev: M + slug: metal-hardrock +- model: program.musicfocus + pk: + fields: + focus: Electronic + abbrev: E + slug: electronic +- model: program.musicfocus + pk: + fields: + focus: Klassik + abbrev: K + slug: klassik +- model: program.musicfocus + pk: + fields: + focus: Oldies + abbrev: O + slug: oldies +- model: program.musicfocus + pk: + fields: + focus: Reggae/Ska + abbrev: Re + slug: reggae-ska +- model: program.musicfocus + pk: + fields: + focus: Hiphop + abbrev: H + slug: hiphop
\ No newline at end of file diff --git a/program/fixtures/rrules.yaml b/program/fixtures/rrules.yaml new file mode 100644 index 0000000..1f09e6a --- /dev/null +++ b/program/fixtures/rrules.yaml @@ -0,0 +1,25 @@ +- model: program.rrule + pk: + fields: + name: einmalig + freq: 0 + count: 1 + bysetpos: 1 +- model: program.rrule + pk: + fields: + name: wöchentlich + freq: 2 + interval: 1 +- model: program.rrule + pk: + fields: + name: zweiwöchentlich + freq: 2 + interval: 2 +- model: program.rrule + pk: + fields: + name: vierwöchentlich + freq: 2 + interval: 4
\ No newline at end of file diff --git a/program/fixtures/showinformation.yaml b/program/fixtures/showinformation.yaml new file mode 100644 index 0000000..56259ec --- /dev/null +++ b/program/fixtures/showinformation.yaml @@ -0,0 +1,48 @@ +- model: program.showinformation + pk: + fields: + information: Interkulturell + abbrev: I + slug: interkulturell +- model: program.showinformation + pk: + fields: + information: Lokalbezug + abbrev: L + slug: lokalbezug +- model: program.showinformation + pk: + fields: + information: Minderheiten + abbrev: Mi + slug: minderheiten +- model: program.showinformation + pk: + fields: + information: Wiederholung + abbrev: W + slug: wiederholung +- model: program.showinformation + pk: + fields: + information: Mehr-/Fremdsprachig + abbrev: M + slug: mehr-fremdsprachig +- model: program.showinformation + pk: + fields: + information: Frauenschwerpunkt + abbrev: F + slug: frauenschwerpunkt +- model: program.showinformation + pk: + fields: + information: Österreichische Musik + abbrev: Ö + slug: osterreichische-musik +- model: program.showinformation + pk: + fields: + information: Sendungsübernahme + abbrev: U + slug: sendungsubernahme
\ No newline at end of file diff --git a/program/fixtures/showtopics.yaml b/program/fixtures/showtopics.yaml new file mode 100644 index 0000000..65c4390 --- /dev/null +++ b/program/fixtures/showtopics.yaml @@ -0,0 +1,30 @@ +- model: program.showtopic + pk: + fields: + topic: Politik/Gesellschaft + abbrev: P + slug: politik-gesellschaft +- model: program.showtopic + pk: + fields: + topic: Natur/Klima/Tiere + abbrev: N + slug: natur-klima-tiere +- model: program.showtopic + pk: + fields: + topic: Kultur/Kunst + abbrev: K + slug: kultur-kunst +- model: program.showtopic + pk: + fields: + topic: Soziales + abbrev: S + slug: soziales +- model: program.showtopic + pk: + fields: + topic: Wissenschaft/Philosophie + abbrev: W + slug: wissenschaft-philosophie
\ No newline at end of file diff --git a/program/management/__init__.py b/program/management/__init__.py new file mode 100644 index 0000000..3aa4ca5 --- /dev/null +++ b/program/management/__init__.py @@ -0,0 +1,2 @@ +__author__ = 'ers' +
\ No newline at end of file diff --git a/program/management/commands/__init__.py b/program/management/commands/__init__.py new file mode 100644 index 0000000..3aa4ca5 --- /dev/null +++ b/program/management/commands/__init__.py @@ -0,0 +1,2 @@ +__author__ = 'ers' +
\ No newline at end of file diff --git a/program/models.py b/program/models.py new file mode 100644 index 0000000..4849fe8 --- /dev/null +++ b/program/models.py @@ -0,0 +1,242 @@ +from django.contrib.auth.models import User +from django.db import models +from django.utils.translation import ugettext_lazy as _ + +from datetime import datetime +from dateutil.relativedelta import relativedelta +from dateutil.rrule import rrule + +class BroadcastFormat(models.Model): + format = models.CharField(_("Format"), max_length=32) + slug = models.SlugField(_("Slug"), max_length=32, unique=True) + + class Meta: + ordering = ('format',) + verbose_name = _("Broadcast format") + verbose_name_plural = _("Broadcast formats") + + def __unicode__(self): + return u'%s' % self.format + +class ShowInformation(models.Model): + information = models.CharField(_("Information"), max_length=32) + abbrev = models.CharField(_("Abbreviation"), max_length=4, unique=True) + slug = models.SlugField(_("Slug"), max_length=32, unique=True) + + class Meta: + ordering = ('information',) + verbose_name = _("Show information") + verbose_name_plural = _("Show information") + + def __unicode__(self): + return u'%s' % self.information + +class ShowTopic(models.Model): + topic = models.CharField(_("Show topic"), max_length=32) + abbrev = models.CharField(_("Abbreviation"), max_length=4, unique=True) + slug = models.SlugField(_("Slug"), max_length=32, unique=True) + + class Meta: + ordering = ('topic',) + verbose_name = _("Show topic") + verbose_name_plural = _("Show topics") + + def __unicode__(self): + return u'%s' % self.topic + +class MusicFocus(models.Model): + focus = models.CharField(_("Focus"), max_length=32) + abbrev = models.CharField(_("Abbreviation"), max_length=4, unique=True) + slug = models.SlugField(_("Slug"), max_length=32, unique=True) + + class Meta: + ordering = ('focus',) + verbose_name = _("Music focus") + verbose_name_plural = _("Music focus") + + def __unicode__(self): + return u'%s' % self.focus + +class Host(models.Model): + name = models.CharField(_("Name"), max_length=128) + email = models.EmailField(_("E-Mail"), blank=True) + website = models.URLField(_("Website"), blank=True) + + class Meta: + ordering = ('name',) + verbose_name = _("Host") + verbose_name_plural = _("Hosts") + + def __unicode__(self): + return u'%s' % self.name + + @models.permalink + def get_absolute_url(self): + return ('host-detail', [str(self.id)]) + +class Show(models.Model): + predecessor = models.ForeignKey('self', blank=True, null=True, related_name='successors', verbose_name=_("Predecessor")) + hosts = models.ManyToManyField(Host, blank=True, null=True, related_name='shows', verbose_name=_("Hosts")) + owners = models.ManyToManyField(User, blank=True, null=True, related_name='shows', verbose_name=_("Owners")) + broadcast_format = models.ForeignKey(BroadcastFormat, related_name='shows', verbose_name=_("Broadcast format")) + show_information = models.ManyToManyField(ShowInformation, blank=True, null=True, related_name='shows', verbose_name=_("Show information")) + show_topic = models.ManyToManyField(ShowTopic, blank=True, null=True, related_name='shows', verbose_name=_("Show topic")) + music_focus = models.ManyToManyField(MusicFocus, blank=True, null=True, related_name='shows', verbose_name=_("Music focus")) + name = models.CharField(_("Name"), max_length=256) + slug = models.CharField(_("Slug"), max_length=256, unique=True) + image = models.ImageField(_("Image"), blank=True, null=True, upload_to='show_images') + short_description = models.CharField(_("Short description"), max_length=64) + description = models.TextField(_("Description")) + email = models.EmailField(_("E-Mail"), blank=True, null=True) + website = models.URLField(_("Website"), blank=True, null=True) + cba_series_id = models.IntegerField(_("CBA series ID"), blank=True, null=True) + created = models.DateTimeField(auto_now_add=True, editable=False) + last_updated = models.DateTimeField(auto_now=True, editable=False) + + class Meta: + ordering = ('slug',) + verbose_name = _("Show") + verbose_name_plural = _("Shows") + + def __unicode__(self): + return u'%s' % self.name + + @models.permalink + def get_absolute_url(self): + return ('show-detail', [self.slug]) + +class RRule(models.Model): + FREQ_CHOICES = ( + (1, _("Monthly")), + (2, _("Weekly")), + (3, _("Daily")), + ) + BYSETPOS_CHOICES = ( + (1, _("First")), + (2, _("Second")), + (3, _("Third")), + (4, _("Fourth")), + (5, _("Fifth")), + (-1, _("Last")), + ) + name = models.CharField(_("Name"), max_length=32, unique=True) + freq = models.IntegerField(_("Frequency"), choices=FREQ_CHOICES) + interval = models.IntegerField(_("Interval"), default=1) + bysetpos = models.IntegerField(_("Set position"), blank=True, choices=BYSETPOS_CHOICES, null=True) + count = models.IntegerField(_("Count"), blank=True, null=True) + + class Meta: + ordering = ('-freq', 'interval', 'bysetpos') + verbose_name = _("Recurrence rule") + verbose_name_plural = _("Recurrence rules") + + def __unicode__(self): + return u'%s' % self.name + +class ProgramSlot(models.Model): + BYWEEKDAY_CHOICES = ( + (0, _("Monday")), + (1, _("Tuesday")), + (2, _("Wednesday")), + (3, _("Thursday")), + (4, _("Friday")), + (5, _("Saturday")), + (6, _("Sunday")), + ) + rrule = models.ForeignKey(RRule, related_name='program_slots', verbose_name=_("Recurrence rule")) + byweekday = models.IntegerField(_("Weekday"), choices=BYWEEKDAY_CHOICES) + show = models.ForeignKey(Show, related_name='program_slots', verbose_name=_("Show")) + dstart = models.DateField(_("First date")) + tstart = models.TimeField(_("Start time")) + tend = models.TimeField(_("End time")) + until = models.DateField(_("Last date")) + is_repetition = models.BooleanField(_("Is repetition"), default=False) + created = models.DateTimeField(auto_now_add=True, editable=False) + last_updated = models.DateTimeField(auto_now=True, editable=False) + + class Meta: + ordering = ('dstart', 'tstart') + unique_together = ('rrule', 'byweekday', 'dstart', 'tstart') + verbose_name = _("Program slot") + verbose_name_plural = _("Program slots") + + def __unicode__(self): + weekday = self.BYWEEKDAY_CHOICES[self.byweekday][1] + tend = self.tend.strftime('%H:%M') + dstart = self.dstart.strftime('%d. %b %Y') + tstart = self.tstart.strftime('%H:%M') + until = self.until.strftime('%d. %b %Y') + + return u'%s, %s, %s - %s, %s - %s' % (self.rrule, weekday, tstart, tend, dstart, until) + + def save(self, *args, **kwargs): + if not self.pk: + super(ProgramSlot, self).save(*args, **kwargs) + + if self.tend < self.tstart: + byweekday = self.byweekday + 1 if self.byweekday < 6 else 0 + else: + byweekday = self.byweekday + + starts = list(rrule(freq=self.rrule.freq, + dtstart=datetime.combine(self.dstart, self.tstart), + interval=self.rrule.interval, + until=self.until+relativedelta(days=+1), + bysetpos=self.rrule.bysetpos, + byweekday=self.byweekday)) + ends = list(rrule(freq=self.rrule.freq, + dtstart=datetime.combine(self.dstart, self.tend), + interval=self.rrule.interval, + until=self.until+relativedelta(days=+1), + bysetpos=self.rrule.bysetpos, + byweekday=byweekday)) + + for k in range(len(starts)): + time_slot = TimeSlot(program_slot=self, start=starts[k], end=ends[k]) + time_slot.save() + +class TimeSlot(models.Model): + program_slot = models.ForeignKey(ProgramSlot, related_name='time_slots', verbose_name=_("Program slot")) + start = models.DateTimeField(_("Start time")) + end = models.DateTimeField(_("End time")) + + class Meta: + ordering = ('start', 'end') + verbose_name = _("Time slot") + verbose_name_plural = _("Time slots") + + def __unicode__(self): + start = self.start.strftime('%d. %b %Y %H:%M') + end = self.end.strftime('%H:%M') + + return u'%s: %s - %s' % (self.show(), start, end) + + def show(self): + return self.program_slot.show + + @models.permalink + def get_absolute_url(self): + return ('timeslot-detail', [self.id]) + +class Note(models.Model): + STATUS_CHOICES = ( + (0, _("Cancellation")), + (1, _("Recommendation")), + (2, _("Repetition")), + ) + time_slot = models.OneToOneField(TimeSlot, verbose_name=_("Time slot")) + owner = models.ForeignKey(User, related_name='notes', verbose_name=_("Owner")) + title = models.CharField(_("Title"), max_length=128) + content = models.TextField(_("Content")) + status = models.IntegerField(_("Status"), choices=STATUS_CHOICES, default=1) + cba_entry_id = models.IntegerField(_("CBA entry ID"), blank=True, null=True) + created = models.DateTimeField(auto_now_add=True, editable=False) + last_updated = models.DateTimeField(auto_now=True, editable=False) + + class Meta: + ordering = ('time_slot',) + verbose_name = _("Note") + verbose_name_plural = _("Notes") + + def __unicode__(self): + return u'%s - %s' % (self.title, self.time_slot)
\ No newline at end of file diff --git a/program/tests.py b/program/tests.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/program/tests.py diff --git a/program/urls.py b/program/urls.py new file mode 100644 index 0000000..850fbdd --- /dev/null +++ b/program/urls.py @@ -0,0 +1,14 @@ +from django.conf.urls.defaults import * +from django.views.generic.detail import DetailView +from django.views.generic.list import ListView + +from models import Host, Show, TimeSlot +from views import ShowListView + +urlpatterns = patterns('', + url('^hosts/$', ListView.as_view(model=Host,context_object_name='host_list')), + url('^host/(?P<pk>\d+)/$', DetailView.as_view(model=Host), name='host-detail'), + url('^shows/$', ShowListView.as_view(model=Show)), + url('^show/(?P<slug>[\w-]+)/$', DetailView.as_view(model=Show), name='show-detail'), + url('^timeslot/(?P<pk>\d+)/$', DetailView.as_view(model=TimeSlot, context_object_name='timeslot'), name='timeslot-detail'), +)
\ No newline at end of file diff --git a/program/views.py b/program/views.py new file mode 100644 index 0000000..c6974b9 --- /dev/null +++ b/program/views.py @@ -0,0 +1,17 @@ +from django.views.generic.list import ListView + +from models import BroadcastFormat, MusicFocus, Show, ShowInformation, ShowTopic + +class ShowListView(ListView): + context_object_name = 'show_list' + model = Show + + def get_context_data(self, **kwargs): + context = super(ShowListView, self).get_context_data(**kwargs) + + context['broadcast_format_list'] = BroadcastFormat.objects.all() + context['music_focus_list'] = MusicFocus.objects.all() + context['show_information_list'] = ShowInformation.objects.all() + context['show_topic_list'] = ShowTopic.objects.all() + + return context
\ No newline at end of file |