summaryrefslogtreecommitdiff
path: root/helsinki
diff options
context:
space:
mode:
authorJohannes Raggam <raggam-nl@adm.at>2011-03-26 20:35:14 (GMT)
committerJohannes Raggam <raggam-nl@adm.at>2011-03-26 20:35:14 (GMT)
commitd277b4a96830dac291fa77c710ffcba1c802407d (patch)
tree4209a83efd4ab96b028b7daa8e89630dfe383e90 /helsinki
parentfaa08b0b5ff0da35708fdbfc0cf2475a051ee6e4 (diff)
refactor project structure
Diffstat (limited to 'helsinki')
-rw-r--r--helsinki/program/__init__.py0
-rw-r--r--helsinki/program/admin.py58
-rw-r--r--helsinki/program/fixtures/broadcastformats.yaml35
-rw-r--r--helsinki/program/fixtures/hosts.yaml4
-rw-r--r--helsinki/program/fixtures/musicfocus.yaml60
-rw-r--r--helsinki/program/fixtures/rrules.yaml29
-rw-r--r--helsinki/program/fixtures/showinformation.yaml48
-rw-r--r--helsinki/program/fixtures/shows.yaml10
-rw-r--r--helsinki/program/fixtures/showtopics.yaml30
-rwxr-xr-xhelsinki/program/manage.py11
-rw-r--r--helsinki/program/management/__init__.py2
-rw-r--r--helsinki/program/management/commands/__init__.py2
-rw-r--r--helsinki/program/management/commands/importhosts.py34
-rw-r--r--helsinki/program/management/commands/importnotes.py62
-rw-r--r--helsinki/program/management/commands/importprogramslots.py96
-rw-r--r--helsinki/program/management/commands/importshows.py67
-rw-r--r--helsinki/program/models.py297
-rw-r--r--helsinki/program/settings.py100
-rw-r--r--helsinki/program/templates/404.html7
-rw-r--r--helsinki/program/templates/500.html11
-rw-r--r--helsinki/program/templates/base.html11
-rw-r--r--helsinki/program/templates/program/current_box.html39
-rw-r--r--helsinki/program/templates/program/day_schedule.html63
-rw-r--r--helsinki/program/templates/program/host_detail.html20
-rw-r--r--helsinki/program/templates/program/host_list.html16
-rw-r--r--helsinki/program/templates/program/recommendations.html21
-rw-r--r--helsinki/program/templates/program/recommendations_box.html20
-rw-r--r--helsinki/program/templates/program/show_detail.html60
-rw-r--r--helsinki/program/templates/program/show_list.html73
-rw-r--r--helsinki/program/templates/program/timeslot_detail.html57
-rw-r--r--helsinki/program/templates/program/week_schedule.html87
-rw-r--r--helsinki/program/urls.py9
-rw-r--r--helsinki/program/urls_program.py20
-rw-r--r--helsinki/program/views.py150
34 files changed, 1609 insertions, 0 deletions
diff --git a/helsinki/program/__init__.py b/helsinki/program/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/helsinki/program/__init__.py
diff --git a/helsinki/program/admin.py b/helsinki/program/admin.py
new file mode 100644
index 0000000..5a6ce7f
--- /dev/null
+++ b/helsinki/program/admin.py
@@ -0,0 +1,58 @@
+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):
+ date_hierarchy = 'start'
+ list_display = ('title', 'show', 'status')
+ list_filter = ('status',)
+ ordering = ('timeslot',)
+
+class TimeSlotInline(admin.TabularInline):
+ model = TimeSlot
+
+class ProgramSlotAdmin(admin.ModelAdmin):
+ date_hierarchy = 'dstart'
+ inlines = (TimeSlotInline,)
+ list_display = ('show', 'byweekday', 'rrule', 'tstart', 'tend', 'dstart', 'until', 'timeslot_count')
+ 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', 'musicfocus', 'showinformation', 'showtopic')
+ inlines = (ProgramSlotInline,)
+ list_display = ('name', 'short_description', 'broadcastformat', 'has_active_programslots')
+ list_filter = ('broadcastformat', 'showinformation', 'showtopic', 'musicfocus',)
+ 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/helsinki/program/fixtures/broadcastformats.yaml b/helsinki/program/fixtures/broadcastformats.yaml
new file mode 100644
index 0000000..84fa335
--- /dev/null
+++ b/helsinki/program/fixtures/broadcastformats.yaml
@@ -0,0 +1,35 @@
+- model: program.broadcastformat
+ pk: 1
+ fields:
+ format: Talk
+ slug: talk
+- model: program.broadcastformat
+ pk: 2
+ fields:
+ format: Musiksendung
+ slug: musiksendung
+- model: program.broadcastformat
+ pk: 3
+ fields:
+ format: Unmoderiertes Musikprogramm
+ slug: unmoderiertes-musikprogramm
+- model: program.broadcastformat
+ pk: 4
+ fields:
+ format: Feature/Magazin
+ slug: feature-magazin
+- model: program.broadcastformat
+ pk: 5
+ fields:
+ format: Experimentell
+ slug: experimentell
+- model: program.broadcastformat
+ pk: 6
+ fields:
+ format: Hörspiel/Literatur
+ slug: horspiel-literatur
+- model: program.broadcastformat
+ pk: 7
+ fields:
+ format: Vortrag/Diskussion
+ slug: vortrag-diskussion \ No newline at end of file
diff --git a/helsinki/program/fixtures/hosts.yaml b/helsinki/program/fixtures/hosts.yaml
new file mode 100644
index 0000000..4cccf3a
--- /dev/null
+++ b/helsinki/program/fixtures/hosts.yaml
@@ -0,0 +1,4 @@
+- model: program.host
+ pk: 1
+ fields:
+ name: Musikredaktion
diff --git a/helsinki/program/fixtures/musicfocus.yaml b/helsinki/program/fixtures/musicfocus.yaml
new file mode 100644
index 0000000..90de149
--- /dev/null
+++ b/helsinki/program/fixtures/musicfocus.yaml
@@ -0,0 +1,60 @@
+- model: program.musicfocus
+ pk: 1
+ fields:
+ focus: Jazz
+ abbrev: J
+ slug: jazz
+- model: program.musicfocus
+ pk: 2
+ fields:
+ focus: Volksmusik/Folk
+ abbrev: V
+ slug: volksmusik-folk
+- model: program.musicfocus
+ pk: 3
+ fields:
+ focus: Experimentelle Musik
+ abbrev: Ex
+ slug: expermentelle-musik
+- model: program.musicfocus
+ pk: 4
+ fields:
+ focus: Rock/Indie
+ abbrev: R
+ slug: rock-indie
+- model: program.musicfocus
+ pk: 5
+ fields:
+ focus: Metal/Hardrock
+ abbrev: M
+ slug: metal-hardrock
+- model: program.musicfocus
+ pk: 6
+ fields:
+ focus: Electronic
+ abbrev: E
+ slug: electronic
+- model: program.musicfocus
+ pk: 7
+ fields:
+ focus: Klassik
+ abbrev: K
+ slug: klassik
+- model: program.musicfocus
+ pk: 8
+ fields:
+ focus: Oldies
+ abbrev: O
+ slug: oldies
+- model: program.musicfocus
+ pk: 9
+ fields:
+ focus: Reggae/Ska
+ abbrev: Re
+ slug: reggae-ska
+- model: program.musicfocus
+ pk: 10
+ fields:
+ focus: Hiphop
+ abbrev: H
+ slug: hiphop \ No newline at end of file
diff --git a/helsinki/program/fixtures/rrules.yaml b/helsinki/program/fixtures/rrules.yaml
new file mode 100644
index 0000000..4095e07
--- /dev/null
+++ b/helsinki/program/fixtures/rrules.yaml
@@ -0,0 +1,29 @@
+- model: program.rrule
+ pk: 1
+ fields:
+ name: einmalig
+ freq: 0
+ count: 1
+- model: program.rrule
+ pk: 2
+ fields:
+ name: täglich
+ freq: 3
+- model: program.rrule
+ pk: 3
+ fields:
+ name: wöchentlich
+ freq: 2
+ interval: 1
+- model: program.rrule
+ pk: 4
+ fields:
+ name: zweiwöchentlich
+ freq: 2
+ interval: 2
+- model: program.rrule
+ pk: 5
+ fields:
+ name: vierwöchentlich
+ freq: 2
+ interval: 4 \ No newline at end of file
diff --git a/helsinki/program/fixtures/showinformation.yaml b/helsinki/program/fixtures/showinformation.yaml
new file mode 100644
index 0000000..cbde529
--- /dev/null
+++ b/helsinki/program/fixtures/showinformation.yaml
@@ -0,0 +1,48 @@
+- model: program.showinformation
+ pk: 1
+ fields:
+ information: Interkulturell
+ abbrev: I
+ slug: interkulturell
+- model: program.showinformation
+ pk: 2
+ fields:
+ information: Lokalbezug
+ abbrev: L
+ slug: lokalbezug
+- model: program.showinformation
+ pk: 3
+ fields:
+ information: Minderheiten
+ abbrev: Mi
+ slug: minderheiten
+- model: program.showinformation
+ pk: 4
+ fields:
+ information: Wiederholung
+ abbrev: W
+ slug: wiederholung
+- model: program.showinformation
+ pk: 5
+ fields:
+ information: Mehr-/Fremdsprachig
+ abbrev: M
+ slug: mehr-fremdsprachig
+- model: program.showinformation
+ pk: 6
+ fields:
+ information: Frauenschwerpunkt
+ abbrev: F
+ slug: frauenschwerpunkt
+- model: program.showinformation
+ pk: 7
+ fields:
+ information: Österreichische Musik
+ abbrev: Ö
+ slug: osterreichische-musik
+- model: program.showinformation
+ pk: 8
+ fields:
+ information: Sendungsübernahme
+ abbrev: U
+ slug: sendungsubernahme \ No newline at end of file
diff --git a/helsinki/program/fixtures/shows.yaml b/helsinki/program/fixtures/shows.yaml
new file mode 100644
index 0000000..f520b26
--- /dev/null
+++ b/helsinki/program/fixtures/shows.yaml
@@ -0,0 +1,10 @@
+- model: program.show
+ pk: 1
+ fields:
+ hosts: [1]
+ broadcastformat: 3
+ name: Musikprogramm
+ slug: musikprogramm
+ description: Unmoderiertes Musikprogramm
+ short_description: Unmoderiertes Musikprogramm
+ email: musikredaktion@helsinki.at
diff --git a/helsinki/program/fixtures/showtopics.yaml b/helsinki/program/fixtures/showtopics.yaml
new file mode 100644
index 0000000..8f12508
--- /dev/null
+++ b/helsinki/program/fixtures/showtopics.yaml
@@ -0,0 +1,30 @@
+- model: program.showtopic
+ pk: 1
+ fields:
+ topic: Politik/Gesellschaft
+ abbrev: P
+ slug: politik-gesellschaft
+- model: program.showtopic
+ pk: 2
+ fields:
+ topic: Natur/Klima/Tiere
+ abbrev: N
+ slug: natur-klima-tiere
+- model: program.showtopic
+ pk: 3
+ fields:
+ topic: Kultur/Kunst
+ abbrev: K
+ slug: kultur-kunst
+- model: program.showtopic
+ pk: 4
+ fields:
+ topic: Soziales
+ abbrev: S
+ slug: soziales
+- model: program.showtopic
+ pk: 5
+ fields:
+ topic: Wissenschaft/Philosophie
+ abbrev: W
+ slug: wissenschaft-philosophie \ No newline at end of file
diff --git a/helsinki/program/manage.py b/helsinki/program/manage.py
new file mode 100755
index 0000000..5e78ea9
--- /dev/null
+++ b/helsinki/program/manage.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+from django.core.management import execute_manager
+try:
+ import settings # Assumed to be in the same directory.
+except ImportError:
+ import sys
+ sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
+ sys.exit(1)
+
+if __name__ == "__main__":
+ execute_manager(settings)
diff --git a/helsinki/program/management/__init__.py b/helsinki/program/management/__init__.py
new file mode 100644
index 0000000..3aa4ca5
--- /dev/null
+++ b/helsinki/program/management/__init__.py
@@ -0,0 +1,2 @@
+__author__ = 'ers'
+ \ No newline at end of file
diff --git a/helsinki/program/management/commands/__init__.py b/helsinki/program/management/commands/__init__.py
new file mode 100644
index 0000000..3aa4ca5
--- /dev/null
+++ b/helsinki/program/management/commands/__init__.py
@@ -0,0 +1,2 @@
+__author__ = 'ers'
+ \ No newline at end of file
diff --git a/helsinki/program/management/commands/importhosts.py b/helsinki/program/management/commands/importhosts.py
new file mode 100644
index 0000000..39a8afd
--- /dev/null
+++ b/helsinki/program/management/commands/importhosts.py
@@ -0,0 +1,34 @@
+from django.core.management.base import NoArgsCommand
+
+import MySQLdb
+
+from helsinki.program.models import Host
+
+USER = 'helsinki'
+PASSWD = 'helsinki'
+DB = 'helsinki'
+
+class Command(NoArgsCommand):
+ help = 'Import hosts from current program'
+
+ def handle_noargs(self, **options):
+ connection = MySQLdb.connect(user=USER, passwd=PASSWD, db=DB)
+ cursor = connection.cursor()
+
+ cursor.execute("""SELECT DISTINCT macher
+FROM sendungen
+WHERE letzter_termin > current_date AND macher != '' AND titel NOT LIKE 'Musikprogramm'""")
+
+ counter = 0
+
+ for row in cursor.fetchall():
+ for macher in row[0].split(','):
+ host = Host(name=macher.strip())
+ host.save()
+
+ counter += 1
+
+ cursor.close()
+ connection.close()
+
+ print '%i hosts imported' % counter
diff --git a/helsinki/program/management/commands/importnotes.py b/helsinki/program/management/commands/importnotes.py
new file mode 100644
index 0000000..19ddfed
--- /dev/null
+++ b/helsinki/program/management/commands/importnotes.py
@@ -0,0 +1,62 @@
+from django.contrib.auth.models import User
+from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
+from django.core.management.base import NoArgsCommand
+from django.utils.html import clean_html, strip_tags
+
+import MySQLdb
+
+from helsinki.program.models import Note, Show, TimeSlot
+
+USER = 'helsinki'
+PASSWD = 'helsinki'
+DB = 'helsinki'
+
+OWNER = User.objects.get(pk=1)
+
+class Command(NoArgsCommand):
+ help = 'Import notes from current program'
+
+ def handle_noargs(self, **options):
+ connection = MySQLdb.connect(user=USER, passwd=PASSWD, db=DB)
+ cursor = connection.cursor()
+
+ cursor.execute("""SELECT n.titel, n.datum, s.titel, n.notiz
+FROM notizen AS n JOIN sendungen AS s ON n.sendung_id=s.id
+WHERE n.sendung_id in (SELECT id FROM sendungen WHERE letzter_termin > current_date) AND n.titel != ''""")
+
+ counter = 0
+ for ntitel, datum, stitel, notiz in cursor.fetchall():
+ ntitel = strip_tags(ntitel)
+ stitel = strip_tags(stitel)
+ notiz = clean_html(notiz)
+
+ if stitel.endswith('(Wiederholung)'):
+ stitel = stitel[:-15]
+
+ if datum:
+ year, month, day = datum.year, datum.month, datum.day
+ try:
+ show = Show.objects.get(name=stitel)
+
+ try:
+ timeslot = TimeSlot.objects.get(programslot__show=show, start__year=year, start__month=month, start__day=day)
+ except ObjectDoesNotExist:
+ print 'no timeslot found for sendung "%s" and datum "%s"' % (stitel, datum)
+ except MultipleObjectsReturned:
+ print 'multiple timeslots found for sendung "%s" and datum "%s"' % (stitel, datum)
+ else:
+ note = Note(timeslot=timeslot, owner=OWNER, title=ntitel, content=notiz)
+
+ try:
+ note.save()
+ except:
+ print 'could not save note "%s" for show "%s" and datum "%s"' % (ntitel, stitel, datum)
+ else:
+ counter += 1
+ except ObjectDoesNotExist:
+ print 'show with name "%s" not found' % stitel
+
+ cursor.close()
+ connection.close()
+
+ print '%i notes imported' % counter
diff --git a/helsinki/program/management/commands/importprogramslots.py b/helsinki/program/management/commands/importprogramslots.py
new file mode 100644
index 0000000..52aa73a
--- /dev/null
+++ b/helsinki/program/management/commands/importprogramslots.py
@@ -0,0 +1,96 @@
+from django.core.exceptions import ObjectDoesNotExist
+from django.core.management.base import NoArgsCommand
+from django.utils.html import strip_tags
+
+from datetime import time
+import MySQLdb
+
+from helsinki.program.models import Show, ProgramSlot, RRule
+
+USER = 'helsinki'
+PASSWD = 'helsinki'
+DB = 'helsinki'
+
+RRULES = {
+ 0: RRule.objects.get(pk=1),
+ 7: RRule.objects.get(pk=3),
+ 14: RRule.objects.get(pk=4),
+ 28: RRule.objects.get(pk=5)
+}
+
+class Command(NoArgsCommand):
+ help = 'Import programslots from the current program'
+
+ def handle_noargs(self, **options):
+ connection = MySQLdb.connect(user=USER, passwd=PASSWD, db=DB)
+ cursor = connection.cursor()
+
+ cursor.execute("""SELECT titel, beginn, ende, erster_termin, letzter_termin, rhytmus, termin
+FROM sendungen
+WHERE letzter_termin > current_date AND titel NOT LIKE 'Musikprogramm' AND titel NOT LIKE '%%(Wiederholung)'""")
+
+ counter = 0
+
+ for titel, beginn, ende, erster_termin, letzter_termin, rhytmus, termin in cursor.fetchall():
+ titel = strip_tags(titel)
+
+ hours, seconds = divmod(beginn.seconds, 3600)
+ minutes, seconds = divmod(seconds, 60)
+ tstart = time(hour=hours, minute=minutes, second=seconds)
+
+ hours, seconds = divmod(ende.seconds, 3600)
+ minutes, seconds = divmod(seconds, 60)
+ tend = time(hour=hours, minute=minutes, second=seconds)
+
+ try:
+ rrule = RRULES[rhytmus]
+ try:
+ show = Show.objects.get(name=titel)
+ except ObjectDoesNotExist:
+ print 'show with name "%s" not found' % titel
+ else:
+ programslot = ProgramSlot(rrule=rrule, byweekday=termin, show=show, dstart=erster_termin, tstart=tstart,
+ tend=tend, until=letzter_termin)
+ try:
+ programslot.save()
+ counter += 1
+ except:
+ pass
+ except KeyError:
+ print 'rhythmus "%i" is not supported for sendung "%s"' % (rhytmus, titel)
+
+ cursor.execute("""SELECT titel, beginn, ende, erster_termin, letzter_termin, rhytmus, termin
+FROM sendungen
+WHERE letzter_termin > current_date AND titel LIKE '%%(Wiederholung)'""")
+
+ for titel, beginn, ende, erster_termin, letzter_termin, rhytmus, termin in cursor.fetchall():
+ titel = strip_tags(titel[:-15])
+
+ hours, seconds = divmod(beginn.seconds, 3600)
+ minutes, seconds = divmod(seconds, 60)
+ tstart = time(hour=hours, minute=minutes, second=seconds)
+
+ hours, seconds = divmod(ende.seconds, 3600)
+ minutes, seconds = divmod(seconds, 60)
+ tend = time(hour=hours, minute=minutes, second=seconds)
+
+ try:
+ rrule = RRULES[rhytmus]
+ try:
+ show = Show.objects.get(name=titel)
+ except ObjectDoesNotExist:
+ print 'show with name "%s" not found' % titel
+ else:
+ programslot = ProgramSlot(rrule=rrule, byweekday=termin, show=show, dstart=erster_termin, tstart=tstart, tend=tend, until=letzter_termin, is_repetition=True)
+ try:
+ programslot.save()
+ counter += 1
+ except:
+ pass
+ except KeyError:
+ print 'rhythmus "%i" is not supported for sendung "%s"' % (rhytmus, titel)
+
+ cursor.close()
+ connection.close()
+
+ print '%i programslots imported' % counter
diff --git a/helsinki/program/management/commands/importshows.py b/helsinki/program/management/commands/importshows.py
new file mode 100644
index 0000000..b013dab
--- /dev/null
+++ b/helsinki/program/management/commands/importshows.py
@@ -0,0 +1,67 @@
+from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
+from django.core.management.base import NoArgsCommand
+from django.template.defaultfilters import slugify
+from django.utils.html import clean_html, strip_tags
+
+import MySQLdb
+
+from helsinki.program.models import BroadcastFormat, Host, Show
+
+USER = 'helsinki'
+PASSWD = 'helsinki'
+DB = 'helsinki'
+
+TALK = BroadcastFormat.objects.get(pk=1)
+
+class Command(NoArgsCommand):
+ help = 'Import shows from the current program'
+
+ def handle_noargs(self, **options):
+ connection = MySQLdb.connect(user=USER, passwd=PASSWD, db=DB)
+ cursor = connection.cursor()
+
+ cursor.execute("""SELECT titel, beschreibung, web, macher
+FROM sendungen
+WHERE letzter_termin > current_date AND titel NOT LIKE 'Musikprogramm' AND titel NOT LIKE '%%(Wiederholung)'
+ORDER BY titel, beginn, ende""")
+
+ counter = 0
+
+ for titel, beschreibung, web, macher in cursor.fetchall():
+ titel = strip_tags(titel)
+ beschreibung = clean_html(beschreibung)
+
+ slug = slugify(titel)
+
+ hosts = []
+
+ for macher in macher.split(','):
+ macher = macher.strip()
+ try:
+ host = Host.objects.get(name=macher)
+ except MultipleObjectsReturned:
+ print 'multiple hosts with name "%s" found' % macher
+ except ObjectDoesNotExist:
+ print 'host with name "%s" not found' % macher
+ else:
+ hosts.append(host)
+
+ try:
+ show = Show.objects.get(name=titel)
+ print 'sendung "%s" already imported as show "%s"' % (titel, show)
+ except ObjectDoesNotExist:
+ show = Show(broadcastformat=TALK, name=titel, slug=slug, short_description='FIXME', description=beschreibung)
+ try:
+ show.save()
+ counter += 1
+ except:
+ print 'sendung "%s" could not be imported' % titel
+ else:
+ for h in hosts:
+ show.hosts.add(h)
+ show.save()
+
+ cursor.close()
+ connection.close()
+
+ print '%i shows imported' % counter
diff --git a/helsinki/program/models.py b/helsinki/program/models.py
new file mode 100644
index 0000000..f6839e2
--- /dev/null
+++ b/helsinki/program/models.py
@@ -0,0 +1,297 @@
+from django.contrib.auth.models import User
+from django.core.exceptions import ObjectDoesNotExist
+from django.db import models
+from django.utils.translation import ugettext_lazy as _
+
+from datetime import date, 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"))
+ broadcastformat = models.ForeignKey(BroadcastFormat, related_name='shows', verbose_name=_("Broadcast format"))
+ showinformation = models.ManyToManyField(ShowInformation, blank=True, null=True, related_name='shows', verbose_name=_("Show information"))
+ showtopic = models.ManyToManyField(ShowTopic, blank=True, null=True, related_name='shows', verbose_name=_("Show topic"))
+ musicfocus = 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=255, 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])
+
+ def has_active_programslots(self):
+ return self.programslots.filter(until__gt=date.today()).count() > 0
+ has_active_programslots.boolean = True
+ has_active_programslots.short_description = _("Has active program slots")
+
+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='programslots', verbose_name=_("Recurrence rule"))
+ byweekday = models.IntegerField(_("Weekday"), choices=BYWEEKDAY_CHOICES)
+ show = models.ForeignKey(Show, related_name='programslots', 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')
+
+ if self.rrule.freq == 0:
+ return u'%s, %s - %s' % (dstart, tstart, tend)
+ if self.rrule.freq == 3:
+ return u'%s, %s - %s' % (self.rrule, tstart, tend)
+ else:
+ return u'%s, %s, %s - %s' % (weekday, self.rrule, tstart, tend)
+
+ def save(self, *args, **kwargs):
+ if not self.pk:
+ super(ProgramSlot, self).save(*args, **kwargs)
+
+ if self.rrule.freq == 0:
+ byweekday_start = None
+ byweekday_end = None
+ elif self.rrule.freq == 3:
+ byweekday_start = (0, 1, 2, 3, 4, 5, 6)
+ byweekday_end = (0, 1, 2, 3, 4, 5, 6)
+ else:
+ byweekday_start = self.byweekday
+
+ if self.tend < self.tstart:
+ byweekday_end = self.byweekday + 1 if self.byweekday < 6 else 0
+ else:
+ byweekday_end = 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=byweekday_start))
+ 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_end))
+
+ for k in range(len(starts)):
+ timeslot = TimeSlot(programslot=self, start=starts[k], end=ends[k])
+ timeslot.save()
+
+ def timeslot_count(self):
+ return self.timeslots.count()
+ timeslot_count.description = _("Time slot count")
+
+class TimeSlotManager(models.Manager):
+ def get_or_create_current(self):
+ try:
+ return TimeSlot.objects.get(start__lte=datetime.now(), end__gte=datetime.now())
+ except ObjectDoesNotExist:
+ once = RRule.objects.get(pk=1)
+ today = date.today().weekday()
+ default = Show.objects.get(pk=1)
+
+ previous = TimeSlot.objects.filter(end__lte=datetime.now()).order_by('-start')[0]
+ next = TimeSlot.objects.filter(start__gte=datetime.now())[0]
+
+ dstart, tstart = previous.end.date(), previous.end.time()
+ until, tend = next.start.date(), next.start.time()
+
+ new_programslot = ProgramSlot(rrule=once, byweekday=today, show=default, dstart=dstart, tstart=tstart, tend=tend, until=until)
+ new_programslot.save()
+
+ return new_programslot.timeslots.all()[0]
+
+class TimeSlot(models.Model):
+ programslot = models.ForeignKey(ProgramSlot, related_name='timeslots', verbose_name=_("Program slot"))
+ start = models.DateTimeField(_("Start time"), unique=True)
+ end = models.DateTimeField(_("End time"))
+ show = models.ForeignKey(Show, editable=False)
+
+ objects = TimeSlotManager()
+
+ 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 save(self, *args, **kwargs):
+ self.show = self.programslot.show
+ super(TimeSlot, self).save(*args, **kwargs)
+
+ @models.permalink
+ def get_absolute_url(self):
+ return ('timeslot-detail', [self.id])
+
+class Note(models.Model):
+ STATUS_CHOICES = (
+ (0, _("Cancellation")),
+ (1, _("Recommendation")),
+ (2, _("Repetition")),
+ )
+ timeslot = models.OneToOneField(TimeSlot, limit_choices_to={'start__gte': datetime.now}, 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)
+ start = models.DateTimeField(editable=False)
+ show = models.ForeignKey(Show, editable=False)
+ created = models.DateTimeField(auto_now_add=True, editable=False)
+ last_updated = models.DateTimeField(auto_now=True, editable=False)
+
+ class Meta:
+ ordering = ('timeslot',)
+ verbose_name = _("Note")
+ verbose_name_plural = _("Notes")
+
+ def __unicode__(self):
+ return u'%s - %s' % (self.title, self.timeslot)
+
+ def save(self, *args, **kwargs):
+ self.start = self.timeslot.start
+ self.show = self.timeslot.programslot.show
+
+ super(Note, self).save(*args, **kwargs)
diff --git a/helsinki/program/settings.py b/helsinki/program/settings.py
new file mode 100644
index 0000000..c5173a5
--- /dev/null
+++ b/helsinki/program/settings.py
@@ -0,0 +1,100 @@
+import os
+
+# Django settings for helsinki project.
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+ # ('Your Name', 'your_email@example.com'),
+)
+
+MANAGERS = ADMINS
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.mysql',
+ 'NAME': 'helsinki2',
+ 'USER': 'helsinki',
+ 'PASSWORD': 'helsinki'
+ }
+}
+
+TIME_ZONE = 'Europe/Vienna'
+
+LANGUAGE_CODE = 'de'
+
+SITE_ID = 1
+
+USE_I18N = True
+
+USE_L10N = True
+
+MEDIA_ROOT = ''
+
+MEDIA_URL = ''
+
+STATIC_ROOT = ''
+
+STATIC_URL = '/static/'
+
+ADMIN_MEDIA_PREFIX = '/static/admin/'
+
+STATICFILES_DIRS = ()
+
+STATICFILES_FINDERS = (
+ 'django.contrib.staticfiles.finders.FileSystemFinder',
+ 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
+# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
+)
+
+SECRET_KEY = 'oepk-$!=)c)7+y%cdz-x46_h5bp!o-*9%dv!(sf=3r4zfqk_(t'
+
+TEMPLATE_LOADERS = (
+ 'django.template.loaders.filesystem.Loader',
+ 'django.template.loaders.app_directories.Loader',
+# 'django.template.loaders.eggs.Loader',
+)
+
+MIDDLEWARE_CLASSES = (
+ 'django.middleware.common.CommonMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.middleware.csrf.CsrfViewMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.contrib.messages.middleware.MessageMiddleware',
+)
+
+ROOT_URLCONF = 'helsinki.program.urls'
+
+TEMPLATE_DIRS = (
+ os.path.join(os.path.dirname(__file__), "templates"),
+)
+
+INSTALLED_APPS = (
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.sites',
+ 'django.contrib.messages',
+ 'django.contrib.staticfiles',
+ 'django.contrib.admin',
+ 'helsinki.program',
+)
+
+LOGGING = {
+ 'version': 1,
+ 'disable_existing_loggers': False,
+ 'handlers': {
+ 'mail_admins': {
+ 'level': 'ERROR',
+ 'class': 'django.utils.log.AdminEmailHandler'
+ }
+ },
+ 'loggers': {
+ 'django.request':{
+ 'handlers': ['mail_admins'],
+ 'level': 'ERROR',
+ 'propagate': True,
+ },
+ }
+}
diff --git a/helsinki/program/templates/404.html b/helsinki/program/templates/404.html
new file mode 100644
index 0000000..6281ba0
--- /dev/null
+++ b/helsinki/program/templates/404.html
@@ -0,0 +1,7 @@
+{% extends "base.html" %}
+
+{% block title %}Seite nicht gefunden{% endblock %}
+
+{% block content %}
+ <p>Es tut uns leid, aber die angeforderte Seite konnte nicht gefunden werden.</p>
+{% endblock %} \ No newline at end of file
diff --git a/helsinki/program/templates/500.html b/helsinki/program/templates/500.html
new file mode 100644
index 0000000..98074ab
--- /dev/null
+++ b/helsinki/program/templates/500.html
@@ -0,0 +1,11 @@
+{% extends "base.html" %}
+
+{% block title %}Serverfehler{% endblock %}
+
+{% block content %}
+ <p>
+ Ein Fehler ist aufgetreten.
+ Dieser Fehler wurde an die Serververwalter per E-Mail gemeldet und sollte in Kürze behoben sein.
+ Vielen Dank für Ihr Verständnis.
+ </p>
+{% endblock %} \ No newline at end of file
diff --git a/helsinki/program/templates/base.html b/helsinki/program/templates/base.html
new file mode 100644
index 0000000..2ed539e
--- /dev/null
+++ b/helsinki/program/templates/base.html
@@ -0,0 +1,11 @@
+<html>
+
+<head>
+ <title>{% block title %}{% endblock %}</title>
+</head>
+
+<body>
+{% block content %}{% endblock %}
+</body>
+
+</html> \ No newline at end of file
diff --git a/helsinki/program/templates/program/current_box.html b/helsinki/program/templates/program/current_box.html
new file mode 100644
index 0000000..d778518
--- /dev/null
+++ b/helsinki/program/templates/program/current_box.html
@@ -0,0 +1,39 @@
+<html>
+<head>
+ <title>Current program box</title>
+ <link href="/site_media/styles/base.css" media="screen" rel="stylesheet" type="text/css" />
+</head>
+<body>
+
+<div id="current">
+ <div id="current-title">Programm derzeit</div>
+
+ <div id="current-timeslot">
+ <div class="start">{{ current.start|date:"H:i" }}</div>
+ <div class="show {{ current.show.broadcastformat.slug }}">
+ <div class="name"><a href="{% url timeslot-detail current.id %}">{{ current.show.name }}</a></div>
+ {% if current.note %}
+ <div class="note-title">{{ current.note.title }}</div>
+ {% else %}
+ <div class="short-description">{{ current.show.short_description }}</div>
+ {% endif %}
+ </div>
+ </div>
+
+ <div id="next-timeslot">
+ <div class="start">{{ next.start|date:"H:i" }}</div>
+ <div class="show {{ next.show.broadcastformat.slug }}">
+ <div class="name"><a href="{% url timeslot-detail next.id %}">{{ next.show.name }}</a></div>
+ </div>
+ </div>
+
+ <div id="after-next-timeslot">
+ <div class="start">{{ after_next.start|date:"H:i" }}</div>
+ <div class="show {{ after_next.show.broadcastformat.slug }}">
+ <div class="name"><a href="{% url timeslot-detail after_next.id %}">{{ after_next.show.name }}</div></a>
+ </div>
+ </div>
+</div>
+
+</body>
+</html> \ No newline at end of file
diff --git a/helsinki/program/templates/program/day_schedule.html b/helsinki/program/templates/program/day_schedule.html
new file mode 100644
index 0000000..6230314
--- /dev/null
+++ b/helsinki/program/templates/program/day_schedule.html
@@ -0,0 +1,63 @@
+<html>
+<head>
+ <title>Day schedule: {{ day|date:"l, d.m.Y" }}</title>
+ <link href="/site_media/styles/base.css" media="screen" rel="stylesheet" type="text/css" />
+</head>
+
+<body>
+
+<div id="calendar"></div>
+
+<div id="recommendations">
+ <div id="recommendations-title">Programmhinweise</div>
+ {% for recommendation in recommendations %}
+ <div class="recommendation {{ recommendation.show.broadcastformat.slug }}">
+ <div class="timeslot-start-end">{{ recommendation.timeslot.start|date:"d.m. H:i" }} - {{ recommendation.timeslot.end|date:"H:i" }}</div>
+ <div class="show-name"><a href="{% url show-detail recommendation.show.slug %}">{{ recommendation.show.name }}</a></div>
+ <div class="note-title"><a href="{% url timeslot-detail recommendation.timeslot.id %}">{{ recommendation.title }}</a></div>
+ </div>
+ {% endfor %}
+</div>
+
+<div id="day-schedule">
+ <div id="title">Tagesansicht</div>
+ <div id="date">{{ day|date:"l, d.m.Y" }}</div>
+ <div id="timeslots">
+ {% for timeslot in timeslots %}
+ <div class="timeslot {{ timeslot.show.broadcastformat }}">
+ <div class="start">{{ timeslot.start|date:"H:i" }}</div>
+ <div class="show-abbrevs">&nbsp;
+ {% for showinformation in timeslot.show.showinformation.all %}
+ {{ showinformation.abbrev }}
+ {% endfor %}
+ {% for showtopic in timeslot.show.showtopic.all %}
+ {{ showtopic.abbrev }}
+ {% endfor %}
+ {% for musicfocus in timeslot.show.musicfocus.all %}
+ {{ musicfocus.abbrev }}
+ {% endfor %}
+ </div>
+ <div class="show">
+ <div class="name"><a href="{% url timeslot-detail timeslot.id %}">{{ timeslot.show.name }}</a></div>
+ {% if timeslot.note %}
+ <div class="note-title">Heute: {{ timeslot.note.title }}</div>
+ {% else %}
+ <div class="short-description">{{ timeslot.show.short_description }}</div>
+ {% endif %}
+ </div>
+ </div>
+ {% endfor %}
+ </div>
+</div>
+
+<div id="broadcastformats">
+ <div id="broadcastformats-title">Legende</div>
+ {% for broadcastformat in broadcastformats %}
+ <div class="{{ broadcastformat.slug }}">
+ <a href="?broadcastformat={{ broadcastformat.slug }}">{{ broadcastformat.format }}</a>
+ </div>
+ {% endfor %}
+</div>
+
+</body>
+</html> \ No newline at end of file
diff --git a/helsinki/program/templates/program/host_detail.html b/helsinki/program/templates/program/host_detail.html
new file mode 100644
index 0000000..b780838
--- /dev/null
+++ b/helsinki/program/templates/program/host_detail.html
@@ -0,0 +1,20 @@
+<html>
+<head>
+ <title>Host detail: {{ host.name }}</title>
+</head>
+<body>
+
+<div id="host-detail">
+ <div id="name">{{ host.name }}</div>
+
+ {% if host.email %}
+ <div id="email">{{ host.email }}</div>
+ {% endif %}
+
+ {% if host.website %}
+ <div id="website">{{ host.website }}</div>
+ {% endif %}
+</div>
+
+</body>
+</html> \ No newline at end of file
diff --git a/helsinki/program/templates/program/host_list.html b/helsinki/program/templates/program/host_list.html
new file mode 100644
index 0000000..365154a
--- /dev/null
+++ b/helsinki/program/templates/program/host_list.html
@@ -0,0 +1,16 @@
+<html>
+<head>
+ <title>Host list</title>
+</head>
+<body>
+
+<div id="host-list">
+{% for host in hosts %}
+ <div class="host">
+ <a href="{% url host-detail host.id %}">{{ host.name }}</a>
+ </div>
+{% endfor %}
+</div>
+
+</body>
+</html> \ No newline at end of file
diff --git a/helsinki/program/templates/program/recommendations.html b/helsinki/program/templates/program/recommendations.html
new file mode 100644
index 0000000..aa5866a
--- /dev/null
+++ b/helsinki/program/templates/program/recommendations.html
@@ -0,0 +1,21 @@
+<html>
+<head>
+ <title>Recomendations</title>
+</head>
+<body>
+
+<div id="recommendations">
+{% for note in recommendations %}
+ <div class="show">
+ <div class="broadcastformat">{{ note.show.broadcastformat }}</div>
+ <div class="timeslot">{{ note.timeslot.start }}</div>
+ <div class="show-name"><a href="{% url show-detail note.show.slug %}">{{ note.show.name }}</a></div>
+ <div class="show-short-description">{{ note.show.short_description }}</div>
+ <div class="note-title">{{ note.title }}</div>
+ <div class="note-content">{{ note.content }}</div>
+ </div>
+{% endfor %}
+</div>
+
+</body>
+</html> \ No newline at end of file
diff --git a/helsinki/program/templates/program/recommendations_box.html b/helsinki/program/templates/program/recommendations_box.html
new file mode 100644
index 0000000..94a55dd
--- /dev/null
+++ b/helsinki/program/templates/program/recommendations_box.html
@@ -0,0 +1,20 @@
+<html>
+<head>
+ <title>Recomendations box</title>
+ <link href="/site_media/styles/base.css" media="screen" rel="stylesheet" type="text/css" />
+</head>
+<body>
+
+<div id="recommendations">
+ <div id="recommendations-title">Programmhinweise</div>
+ {% for recommendation in recommendations %}
+ <div class="recommendation {{ recommendation.show.broadcastformat.slug }}">
+ <div class="timeslot-start-end">{{ recommendation.timeslot.start|date:"d.m. H:i" }}-{{ recommendation.timeslot.end|date:"H:i" }}</div>
+ <div class="show-name"><a href="{% url show-detail recommendation.show.slug %}">{{ recommendation.show.name }}</a></div>
+ <div class="note-title"><a href="{% url timeslot-detail recommendation.timeslot.id %}">{{ recommendation.title }}</a></div>
+ </div>
+ {% endfor %}
+</div>
+
+</body>
+</html> \ No newline at end of file
diff --git a/helsinki/program/templates/program/show_detail.html b/helsinki/program/templates/program/show_detail.html
new file mode 100644
index 0000000..05e678c
--- /dev/null
+++ b/helsinki/program/templates/program/show_detail.html
@@ -0,0 +1,60 @@
+<html>
+<head>
+ <title>Show detail: {{ show.name }}</title>
+</head>
+<body>
+
+<div id="calendar"></div>
+
+<div id="show-detail">
+ <div id="name">{{ show.name }}</div>
+
+ <div id="abbrevs">
+ {% for topic in show.showtopic.all %}
+ <span class="topic-abbrev">{{ topic.abbrev }}</span>
+ {% endfor %}
+
+ {% for information in show.showinformation.all %}
+ <span class="information-abbrev">{{ information.abbrev }}</span>
+ {% endfor %}
+
+ {% for focus in show.musicfocus.all %}
+ <span class="focus-abbrev">{{ focus.abbrev }}</span>
+ {% endfor %}
+
+ <span class="broadcastformat-abbrev">{{ show.broadcastformat.abbrev }}</span>
+ </div>
+
+ <div id="programslots">
+ {% for slot in show.programslots.all %}
+ <div class="programslot">{{ slot }}</div>
+ {% endfor %}
+ </div>
+
+ <div id="broadcastformat">{{ show.broadcastformat.format }}</div>
+
+ <div id="hosts">
+ {% for host in show.hosts.all %}
+ <div class="host">{{ host }}</div>
+ {% endfor %}
+ </div>
+
+ <div id="short-description">{{ show.short_description }}</div>
+
+ <div id="description">{{ show.description }}</div>
+
+ {% if show.email %}
+ <div id="email"><a href="mailto:{{ show.email }}">{{ show.email }}</a></div>
+ {% endif %}
+
+ {% if show.website %}
+ <div id="website"><a href="{{ show.website }}">{{ show.website }}</a></div>
+ {% endif %}
+
+ {% if show.cba_series_id %}
+ <div id="cba-series-id"><a href="http://cba.fro.at/series/{{ show.cba_series_id }}">CBA</a></div>
+ {% endif %}
+</div>
+
+</body>
+</html> \ No newline at end of file
diff --git a/helsinki/program/templates/program/show_list.html b/helsinki/program/templates/program/show_list.html
new file mode 100644
index 0000000..7643087
--- /dev/null
+++ b/helsinki/program/templates/program/show_list.html
@@ -0,0 +1,73 @@
+<html>
+<head>
+ <title>Show list</title>
+</head>
+<body>
+
+<div id="showtopic-list">
+{% for topic in showtopics %}
+ <div class="showtopic">
+ <span class="abbrev">{{ topic.abbrev }}</span>
+ <span class="topic">{{ topic }}</span>
+ </div>
+{% endfor %}
+</div>
+
+<div id="showinformation-list">
+{% for information in showinformations %}
+ <div class="showinformation">
+ <span class="abbrev">{{ information.abbrev }}</span>
+ <span class="information">{{ information }}</span>
+ </div>
+{% endfor %}
+</div>
+
+<div id="musicfocus-list">
+{% for focus in musicfoci %}
+ <div class="musicfocus">
+ <span class="abbrev">{{ focus.abbrev }}</span>
+ <span class="focus">{{ focus }}</span>
+ </div>
+{% endfor %}
+</div>
+
+<div id="show-list">
+{% for show in shows %}
+ <div class="show">
+ <div class="abbrevs">
+ {% for topic in show.showtopic.all %}
+ <span class="topic-abbrev">{{ topic.abbrev }}</span>
+ {% endfor %}
+
+ {% for information in show.showinformation.all %}
+ <span class="information-abbrev">{{ information.abbrev }}</span>
+ {% endfor %}
+
+ {% for focus in show.musicfocus.all %}
+ <span class="focus-abbrev">{{ focus.abbrev }}</span>
+ {% endfor %}
+
+ <span class="broadcastformat-abbrev">{{ show.broadcastformat.abbrev }}</span>
+ </div>
+
+ <div class="name"><a href="{% url show-detail show.slug %} ">{{ show.name }}</a></div>
+
+ <div class="programslots">
+ {% for slot in show.programslots.all %}
+ <div class="programslot">{{ slot }}</div>
+ {% endfor %}
+ </div>
+
+ <div class="short-description">{{ show.short_description }}</div>
+ </div>
+{% endfor %}
+</div>
+
+<div id="broadcastformat-list">
+{% for format in broadcastformats %}
+ <div class="broadcastformat">{{ format }}</div>
+{% endfor %}
+</div>
+
+</body>
+</html> \ No newline at end of file
diff --git a/helsinki/program/templates/program/timeslot_detail.html b/helsinki/program/templates/program/timeslot_detail.html
new file mode 100644
index 0000000..f445f5d
--- /dev/null
+++ b/helsinki/program/templates/program/timeslot_detail.html
@@ -0,0 +1,57 @@
+<html>
+<head>
+ <title>Timeslot detail: {{ timeslot }}</title>
+</head>
+<body>
+
+<div id="calendar"></div>
+
+<div id="timeslot-detail">
+ <div id="name">{{ timeslot.show.name }}</div>
+
+ <div id="abbrevs">
+ {% for topic in timeslot.show.showtopic.all %}
+ <span class="topic-abbrev">{{ topic.abbrev }}</span>
+ {% endfor %}
+
+ {% for information in timeslot.show.showinformation.all %}
+ <span class="information-abbrev">{{ information.abbrev }}</span>
+ {% endfor %}
+
+ {% for focus in timeslot.show.musicfocus.all %}
+ <span class="focus-abbrev">{{ focus.abbrev }}</span>
+ {% endfor %}
+
+ <span class="broadcastformat-abbrev">{{ timeslot.show.broadcastformat.abbrev }}</span>
+ </div>
+
+ <div id="programslots">
+ {% for slot in timeslot.show.programslots.all %}
+ <div class="programslot">{{ slot }}</div>
+ {% endfor %}
+ </div>
+
+ <div id="broadcastformat">{{ timeslot.show.broadcastformat.format }}</div>
+
+ <div id="hosts">
+ {% for host in timeslot.show.hosts.all %}
+ <div class="host">{{ host }}</div>
+ {% endfor %}
+ </div>
+
+ <div id="short-description">{{ timeslot.show.short_description }}</div>
+
+ <div id="description">{{ timeslot.show.description }}</div>
+
+ <div id="note">
+ {% if timeslot.note %}
+ <div class="note">
+ <div class="title">{{ timeslot.note.title }}</div>
+ <div class="content">{{ timeslot.note.content }}</div>
+ </div>
+ {% endif %}
+ </div>
+</div>
+
+</body>
+</html> \ No newline at end of file
diff --git a/helsinki/program/templates/program/week_schedule.html b/helsinki/program/templates/program/week_schedule.html
new file mode 100644
index 0000000..2969d28
--- /dev/null
+++ b/helsinki/program/templates/program/week_schedule.html
@@ -0,0 +1,87 @@
+<html>
+<head>
+ <title>Week schedule</title>
+</head>
+
+<body>
+
+<div id="week-schedule">
+ <div id="time">
+ <div class="1hour">06:00</div>
+ <div class="1hour">07:00</div>
+ <div class="1hour">08:00</div>
+ <div class="1hour">09:00</div>
+ <div class="1hour">10:00</div>
+ <div class="1hour">11:00</div>
+ <div class="1hour">12:00</div>
+ <div class="1hour">13:00</div>
+ <div class="1hour">14:00</div>
+ <div class="1hour">15:00</div>
+ <div class="1hour">16:00</div>
+ <div class="1hour">17:00</div>
+ <div class="1hour">18:00</div>
+ <div class="1hour">19:00</div>
+ <div class="1hour">20:00</div>
+ <div class="1hour">21:00</div>
+ <div class="1hour">22:00</div>
+ <div class="1hour">23:00</div>
+ <div class="1hour">00:00</div>
+ <div class="1hour">01:00</div>
+ <div class="1hour">02:00</div>
+ <div class="1hour">03:00</div>
+ <div class="1hour">04:00</div>
+ <div class="1hour">05:00</div>
+ </div>
+
+ <div id="monday">
+ <div class="weekday">{{ monday|date:"l d.m.Y" }}</div>
+ {% for timeslot in monday_timeslots %}
+ <div class="timeslot {{ timeslot.show.broadcastformat.slug }}"><a href="{% url timeslot-detail timeslot.id %}">{{ timeslot.show.name }}</a></div>
+ {% endfor %}
+ </div>
+
+ <div id="tuesday">
+ <div class="weekday">{{ tuesday|date:"l d.m.Y" }}</div>
+ {% for timeslot in tuesday_timeslots %}
+ <div class="timeslot {{ timeslot.show.broadcastformat.slug }}"><a href="{% url timeslot-detail timeslot.id %}">{{ timeslot.show.name }}</a></div>
+ {% endfor %}
+ </div>
+
+ <div id="wednesday">
+ <div class="weekday">{{ wednesday|date:"l d.m.Y" }}</div>
+ {% for timeslot in wednesday_timeslots %}
+ <div class="timeslot {{ timeslot.show.broadcastformat.slug }}"><a href="{% url timeslot-detail timeslot.id %}">{{ timeslot.show.name }}</a></div>
+ {% endfor %}
+ </div>
+
+ <div id="thursday">
+ <div class="weekday">{{ thursday|date:"l d.m.Y" }}</div>
+ {% for timeslot in thursday_timeslots %}
+ <div class="timeslot {{ timeslot.show.broadcastformat.slug }}"><a href="{% url timeslot-detail timeslot.id %}">{{ timeslot.show.name }}</a></div>
+ {% endfor %}
+ </div>
+
+ <div id="friday">
+ <div class="weekday">{{ friday|date:"l d.m.Y" }}</div>
+ {% for timeslot in friday_timeslots %}
+ <div class="timeslot {{ timeslot.show.broadcastformat.slug }}"><a href="{% url timeslot-detail timeslot.id %}">{{ timeslot.show.name }}</a></div>
+ {% endfor %}
+ </div>
+
+ <div id="saturday">
+ <div class="weekday">{{ saturday|date:"l d.m.Y" }}</div>
+ {% for timeslot in saturday_timeslots %}
+ <div class="timeslot {{ timeslot.show.broadcastformat.slug }}"><a href="{% url timeslot-detail timeslot.id %}">{{ timeslot.show.name }}</a></div>
+ {% endfor %}
+ </div>
+
+ <div id="sunday">
+ <div class="weekday">{{ sunday|date:"l d.m.Y" }}</div>
+ {% for timeslot in sunday_timeslots %}
+ <div class="timeslot {{ timeslot.show.broadcastformat.slug }}"><a href="{% url timeslot-detail timeslot.id %}">{{ timeslot.show.name }}</a></div>
+ {% endfor %}
+ </div>
+</div>
+
+</body>
+</html>
diff --git a/helsinki/program/urls.py b/helsinki/program/urls.py
new file mode 100644
index 0000000..9de7b46
--- /dev/null
+++ b/helsinki/program/urls.py
@@ -0,0 +1,9 @@
+from django.conf.urls.defaults import *
+from django.contrib import admin
+
+admin.autodiscover()
+
+urlpatterns = patterns('',
+ (r'^admin/', include(admin.site.urls)),
+ (r'^program/', include('helsinki.program.urls_program')),
+)
diff --git a/helsinki/program/urls_program.py b/helsinki/program/urls_program.py
new file mode 100644
index 0000000..caa302b
--- /dev/null
+++ b/helsinki/program/urls_program.py
@@ -0,0 +1,20 @@
+from django.conf.urls.defaults import *
+from django.views.generic.detail import DetailView
+from django.views.generic.list import ListView
+
+from helsinki.program.models import Host, Show, TimeSlot
+from helsinki.program.views import CurrentShowView, DayScheduleView, RecommendationsView, ShowListView, TodayScheduleView, WeekScheduleView
+
+urlpatterns = patterns('',
+ ('^$', TodayScheduleView.as_view()),
+ ('^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$', DayScheduleView.as_view()),
+ ('^(?P<year>\d{4})/(?P<week>\d{1,2})/$', WeekScheduleView.as_view()),
+ ('^current_box/$', CurrentShowView.as_view()),
+ ('^hosts/$', ListView.as_view(model=Host, context_object_name='hosts')),
+ url('^host/(?P<pk>\d+)/$', DetailView.as_view(model=Host), name='host-detail'),
+ ('^recommendations/$', RecommendationsView.as_view()),
+ ('^recommendations_box/$', RecommendationsView.as_view(template_name='program/recommendations_box.html')),
+ ('^shows/$', ShowListView.as_view()),
+ url('^show/(?P<slug>[\w-]+)/$', DetailView.as_view(model=Show), name='show-detail'),
+ url('^(?P<pk>\d+)/$', DetailView.as_view(model=TimeSlot), name='timeslot-detail'),
+)
diff --git a/helsinki/program/views.py b/helsinki/program/views.py
new file mode 100644
index 0000000..b118161
--- /dev/null
+++ b/helsinki/program/views.py
@@ -0,0 +1,150 @@
+from django.views.generic.list import ListView
+from django.views.generic.base import TemplateView
+from django.shortcuts import get_object_or_404
+
+from helsinki.program.models import BroadcastFormat, MusicFocus, Note, Show, ShowInformation, ShowTopic, TimeSlot
+
+from datetime import date, datetime, time, timedelta
+
+class ShowListView(ListView):
+ context_object_name = 'shows'
+
+ def get_context_data(self, **kwargs):
+ context = super(ShowListView, self).get_context_data(**kwargs)
+
+ context['broadcastformats'] = BroadcastFormat.objects.all()
+ context['musicfoci'] = MusicFocus.objects.all()
+ context['showinformations'] = ShowInformation.objects.all()
+ context['showtopics'] = ShowTopic.objects.all()
+
+ return context
+
+ def get_queryset(self):
+ if 'broadcastformat' in self.request.GET:
+ broadcastformat = get_object_or_404(BroadcastFormat, slug=self.request.GET['broadcastformat'])
+
+ return Show.objects.filter(broadcastformat=broadcastformat)
+ elif 'musicfocus' in self.request.GET:
+ musicfocus = get_object_or_404(MusicFocus, slug=self.request.GET['musicfocus'])
+
+ return Show.objects.filter(musicfocus=musicfocus)
+ elif 'showinformation' in self.request.GET:
+ showinformation = get_object_or_404(ShowInformation, slug=self.request.GET['showinformation'])
+
+ return Show.objects.filter(showinformation=showinformation)
+ elif 'showtopic' in self.request.GET:
+ showtopic = get_object_or_404(ShowTopic, slug=self.request.GET['showtopic'])
+
+ return Show.objects.filter(showtopic=showtopic)
+ else:
+ return Show.objects.all()
+
+class RecommendationsView(ListView):
+ context_object_name = 'recommendations'
+ template_name = 'program/recommendations.html'
+
+ def get_queryset(self):
+ now = datetime.now()
+ in_one_week = now + timedelta(weeks=1)
+
+ return Note.objects.filter(status=1, timeslot__start__range=(now, in_one_week))[:10]
+
+class TodayScheduleView(TemplateView):
+ template_name = 'program/day_schedule.html'
+
+ def get_context_data(self, **kwargs):
+ context = super(TodayScheduleView, self).get_context_data(**kwargs)
+
+ now = datetime.now()
+ today = datetime.combine(date.today(), time(6, 0))
+ tomorrow = datetime.combine(date.today()+timedelta(days=1), time(6, 0))
+
+ context['day'] = today
+ context['broadcastformats'] = BroadcastFormat.objects.all()
+ context['recommendations'] = Note.objects.filter(status=1, timeslot__start__range=(now, tomorrow))
+
+ if 'broadcastformat' in self.request.GET:
+ broadcastformat = get_object_or_404(BroadcastFormat, slug=self.request.GET['broadcastformat'])
+
+ context['timeslots'] = TimeSlot.objects.filter(start__range=(today, tomorrow), show__broadcastformat=broadcastformat)
+ else:
+ context['timeslots'] = TimeSlot.objects.filter(start__range=(today, tomorrow))
+
+ return context
+
+class DayScheduleView(TemplateView):
+ template_name = 'program/day_schedule.html'
+
+ def get_context_data(self, **kwargs):
+ context = super(DayScheduleView, self).get_context_data(**kwargs)
+
+ year = context['params']['year']
+ month = context['params']['month']
+ day = context['params']['day']
+
+ # start the day at 6
+ this_day = datetime.strptime('%s__%s__%s__06__00' % (year, month, day), '%Y__%m__%d__%H__%M')
+ that_day = this_day+timedelta(days=1)
+
+ context['day'] = this_day
+ context['broadcastformats'] = BroadcastFormat.objects.all()
+ context['recommendations'] = Note.objects.filter(status=1, timeslot__start__range=(this_day, that_day))
+
+ if 'broadcastformat' in self.request.GET:
+ broadcastformat = get_object_or_404(BroadcastFormat, slug=self.request.GET['broadcastformat'])
+
+ context['timeslots'] = TimeSlot.objects.filter(start__range=(this_day, that_day), show__broadcastformat=broadcastformat)
+ else:
+ context['timeslots'] = TimeSlot.objects.filter(start__range=(this_day, that_day))
+
+ return context
+
+class CurrentShowView(TemplateView):
+ template_name = 'program/current_box.html'
+
+ def get_context_data(self, **kwargs):
+ context = super(CurrentShowView, self).get_context_data(**kwargs)
+
+ context['current'] = TimeSlot.objects.get_or_create_current()
+ context['next'] = TimeSlot.objects.get_or_create_current().get_next_by_start()
+ context['after_next'] = TimeSlot.objects.get_or_create_current().get_next_by_start().get_next_by_start()
+
+ return context
+
+class WeekScheduleView(TemplateView):
+ template_name = 'program/week_schedule.html'
+
+ def get_context_data(self, **kwargs):
+ context = super(WeekScheduleView, self).get_context_data(**kwargs)
+
+ year = context['params']['year']
+ week = context['params']['week']
+
+ # start the day at 6
+ monday = datetime.strptime('%s__%s__1__06__00' % (year, week), '%Y__%W__%w__%H__%M')
+
+ tuesday = monday+timedelta(days=1)
+ wednesday = monday+timedelta(days=2)
+ thursday = monday+timedelta(days=3)
+ friday = monday+timedelta(days=4)
+ saturday = monday+timedelta(days=5)
+ sunday = monday+timedelta(days=6)
+ next_monday = monday+timedelta(days=7)
+
+ context['monday'] = monday
+ context['tuesday'] = tuesday
+ context['wednesday'] = wednesday
+ context['thursday'] = thursday
+ context['friday'] = friday
+ context['saturday'] = saturday
+ context['sunday'] = sunday
+
+ context['monday_timeslots'] = TimeSlot.objects.filter(start__range=(monday, tuesday))
+ context['tuesday_timeslots'] = TimeSlot.objects.filter(start__range=(tuesday, wednesday))
+ context['wednesday_timeslots'] = TimeSlot.objects.filter(start__range=(wednesday, thursday))
+ context['thursday_timeslots'] = TimeSlot.objects.filter(start__range=(thursday, friday))
+ context['friday_timeslots'] = TimeSlot.objects.filter(start__range=(friday, saturday))
+ context['saturday_timeslots'] = TimeSlot.objects.filter(start__range=(saturday, sunday))
+ context['sunday_timeslots'] = TimeSlot.objects.filter(start__range=(sunday, next_monday))
+
+ return context