summaryrefslogtreecommitdiff
path: root/program
diff options
context:
space:
mode:
authorErnesto Rico-Schmidt <e.rico.schmidt@gmail.com>2011-03-12 15:14:15 (GMT)
committerErnesto Rico-Schmidt <e.rico.schmidt@gmail.com>2011-03-12 15:14:15 (GMT)
commit3e1c4f43fb5ea31d729f92a1bc71b622c2531ab2 (patch)
tree756406f791b2ca8915e39701e534fa19a27b7539 /program
parent235719f0621b5e36d877d76cfaf40cdb43033a6e (diff)
renamed model attributes to be more consistent, updated templates accordingly. added recommendations view and template.
Diffstat (limited to 'program')
-rw-r--r--program/admin.py10
-rw-r--r--program/models.py34
-rw-r--r--program/urls.py5
-rw-r--r--program/views.py23
4 files changed, 44 insertions, 28 deletions
diff --git a/program/admin.py b/program/admin.py
index 642beaf..25ed87e 100644
--- a/program/admin.py
+++ b/program/admin.py
@@ -20,7 +20,7 @@ class ShowTopicAdmin(admin.ModelAdmin):
class NoteAdmin(admin.ModelAdmin):
list_filter = ('status',)
- ordering = ('time_slot',)
+ ordering = ('timeslot',)
class TimeSlotInline(admin.TabularInline):
model = TimeSlot
@@ -28,7 +28,7 @@ class TimeSlotInline(admin.TabularInline):
class ProgramSlotAdmin(admin.ModelAdmin):
date_hierarchy = 'dstart'
inlines = (TimeSlotInline,)
- list_display = ('show', 'byweekday', 'rrule', 'tstart', 'tend', 'dstart', 'until')
+ list_display = ('show', 'byweekday', 'rrule', 'tstart', 'tend', 'dstart', 'until', 'timeslot_count')
list_filter = ('byweekday', 'rrule', 'is_repetition')
ordering = ('byweekday', 'dstart')
search_fields = ('show__name',)
@@ -37,10 +37,10 @@ class ProgramSlotInline(admin.TabularInline):
model = ProgramSlot
class ShowAdmin(admin.ModelAdmin):
- filter_horizontal = ('hosts', 'owners', 'music_focus', 'show_information', 'show_topic')
+ filter_horizontal = ('hosts', 'owners', 'musicfocus', 'showinformation', 'showtopic')
inlines = (ProgramSlotInline,)
- list_display = ('name', 'short_description', 'broadcast_format')
- list_filter = ('broadcast_format', 'show_information', 'show_topic', 'music_focus',)
+ list_display = ('name', 'short_description', 'broadcastformat')
+ list_filter = ('broadcastformat', 'showinformation', 'showtopic', 'musicfocus',)
ordering = ('slug',)
prepopulated_fields = {'slug': ('name',)}
search_fields = ('name', 'short_description', 'description')
diff --git a/program/models.py b/program/models.py
index 74f660a..9c51541 100644
--- a/program/models.py
+++ b/program/models.py
@@ -78,10 +78,10 @@ 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"))
+ 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=256, unique=True)
image = models.ImageField(_("Image"), blank=True, null=True, upload_to='show_images')
@@ -143,9 +143,9 @@ class ProgramSlot(models.Model):
(5, _("Saturday")),
(6, _("Sunday")),
)
- rrule = models.ForeignKey(RRule, related_name='program_slots', verbose_name=_("Recurrence rule"))
+ rrule = models.ForeignKey(RRule, related_name='programslots', verbose_name=_("Recurrence rule"))
byweekday = models.IntegerField(_("Weekday"), choices=BYWEEKDAY_CHOICES)
- show = models.ForeignKey(Show, related_name='program_slots', verbose_name=_("Show"))
+ 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"))
@@ -209,11 +209,15 @@ class ProgramSlot(models.Model):
byweekday=byweekday))
for k in range(len(starts)):
- time_slot = TimeSlot(program_slot=self, start=starts[k], end=ends[k])
- time_slot.save()
+ 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 TimeSlot(models.Model):
- program_slot = models.ForeignKey(ProgramSlot, related_name='time_slots', verbose_name=_("Program slot"))
+ programslot = models.ForeignKey(ProgramSlot, related_name='timeslots', verbose_name=_("Program slot"))
start = models.DateTimeField(_("Start time"))
end = models.DateTimeField(_("End time"))
@@ -229,7 +233,7 @@ class TimeSlot(models.Model):
return u'%s: %s - %s' % (self.show(), start, end)
def show(self):
- return self.program_slot.show
+ return self.programslot.show
@models.permalink
def get_absolute_url(self):
@@ -241,7 +245,7 @@ class Note(models.Model):
(1, _("Recommendation")),
(2, _("Repetition")),
)
- time_slot = models.OneToOneField(TimeSlot, verbose_name=_("Time slot"))
+ timeslot = 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"))
@@ -251,10 +255,12 @@ class Note(models.Model):
last_updated = models.DateTimeField(auto_now=True, editable=False)
class Meta:
- ordering = ('time_slot',)
+ ordering = ('timeslot',)
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
+ return u'%s - %s' % (self.title, self.timeslot)
+
+ def show(self):
+ return self.timeslot.programslot.show
diff --git a/program/urls.py b/program/urls.py
index 850fbdd..9dfc811 100644
--- a/program/urls.py
+++ b/program/urls.py
@@ -3,12 +3,13 @@ from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from models import Host, Show, TimeSlot
-from views import ShowListView
+from views import RecommendationsView, 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('^recommendations/$', RecommendationsView.as_view()),
+ url('^shows/$', ShowListView.as_view()),
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
index c6974b9..73a1298 100644
--- a/program/views.py
+++ b/program/views.py
@@ -1,6 +1,8 @@
-from django.views.generic.list import ListView
+from django.views.generic import ListView
-from models import BroadcastFormat, MusicFocus, Show, ShowInformation, ShowTopic
+from models import BroadcastFormat, MusicFocus, Note, Show, ShowInformation, ShowTopic
+
+from datetime import datetime, timedelta
class ShowListView(ListView):
context_object_name = 'show_list'
@@ -9,9 +11,16 @@ class ShowListView(ListView):
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()
+ context['broadcastformat_list'] = BroadcastFormat.objects.all()
+ context['musicfocus_list'] = MusicFocus.objects.all()
+ context['showinformation_list'] = ShowInformation.objects.all()
+ context['showtopic_list'] = ShowTopic.objects.all()
+
+ return context
- return context \ No newline at end of file
+class RecommendationsView(ListView):
+ now = datetime.now()
+ in_one_week = now + timedelta(weeks=1)
+ context_object_name = 'recommendation_list'
+ template_name = 'program/recommendations.html'
+ queryset = Note.objects.filter(status=1, timeslot__start__range=(now, in_one_week))[:10]