Skip to content
Snippets Groups Projects
Commit 36d8f7e5 authored by Ernesto Rico Schmidt's avatar Ernesto Rico Schmidt
Browse files

First commit

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 686 additions and 0 deletions
*.pyc
*.sqlite
\ No newline at end of file
LICENSE 0 → 100644
Copyright (c) 2011, Ernesto Rico-Schmidt
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
Neither the name of the author nor the names of its contributors may be
used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
README 0 → 100644
This file was created by PyCharm 1.1.1 for binding GitHub repository
\ No newline at end of file
Requirements
============
- Django 1.3: http://www.djangoproject.com/download/
- PIL: http://www.pythonware.com/products/pil/
- python-dateutil: http://pypi.python.org/pypi/python-dateutil/1.5
- PyYAML: http://pypi.python.org/pypi/PyYAML/3.09
#!/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)
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
- 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
- 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
- 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
- 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
- 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
__author__ = 'ers'
\ No newline at end of file
__author__ = 'ers'
\ No newline at end of file
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
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
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
# 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.sqlite3',
'NAME': 'helsinki.data',
}
}
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.urls'
TEMPLATE_DIRS = ('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,
},
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment