From 3e1c4f43fb5ea31d729f92a1bc71b622c2531ab2 Mon Sep 17 00:00:00 2001 From: Ernesto Rico-Schmidt Date: Sat, 12 Mar 2011 16:14:15 +0100 Subject: renamed model attributes to be more consistent, updated templates accordingly. added recommendations view and template. 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\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[\w-]+)/$', DetailView.as_view(model=Show), name='show-detail'), url('^timeslot/(?P\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] diff --git a/templates/program/host_detail.html b/templates/program/host_detail.html index a632a20..b780838 100644 --- a/templates/program/host_detail.html +++ b/templates/program/host_detail.html @@ -5,9 +5,16 @@
- {{ host.name }} - {{ host.email }} - {{ host.website }} +
{{ host.name }}
+ + {% if host.email %} +
{{ host.email }}
+ {% endif %} + + {% if host.website %} +
{{ host.website }}
+ {% endif %}
+ \ No newline at end of file diff --git a/templates/program/host_list.html b/templates/program/host_list.html index fb19e47..ee67192 100644 --- a/templates/program/host_list.html +++ b/templates/program/host_list.html @@ -5,11 +5,12 @@
- {% for host in host_list %} +{% for host in host_list %} - {% endfor %} +{% endfor %}
+ \ No newline at end of file diff --git a/templates/program/recommendations.html b/templates/program/recommendations.html new file mode 100644 index 0000000..499fe4e --- /dev/null +++ b/templates/program/recommendations.html @@ -0,0 +1,20 @@ + + + Recomendations + + + +
+{% for note in recommendation_list %} +
+
{{ note.show.broadcastformat }}
+
{{ note.timeslot.start }}
+ +
{{ note.show.short_description }}
+ +
+{% endfor %} +
+ + + \ No newline at end of file diff --git a/templates/program/show_detail.html b/templates/program/show_detail.html index 4de24c5..e2216ff 100644 --- a/templates/program/show_detail.html +++ b/templates/program/show_detail.html @@ -10,25 +10,28 @@
{{ show.name }}
- {% for topic in show.show_topic.all %} + {% for topic in show.showtopic.all %} {{ topic.abbrev }} {% endfor %} - {% for information in show.show_information.all %} + + {% for information in show.showinformation.all %} {{ information.abbrev }} {% endfor %} - {% for focus in show.music_focus.all %} + + {% for focus in show.musicfocus.all %} {{ focus.abbrev }} {% endfor %} - {{ show.broadcast_format.abbrev }} + + {{ show.broadcastformat.abbrev }}
- {% for slot in show.program_slots.all %} -
{{ slot }}
+ {% for slot in show.programslots.all %} +
{{ slot }}
{% endfor %}
-
{{ show.broadcast_format.format }}
+
{{ show.broadcastformat.format }}
{% for host in show.hosts.all %} @@ -37,18 +40,21 @@
{{ show.short_description }}
+
{{ show.description }}
+ {% if show.email %} {% endif %} + {% if show.website %} {% endif %} + {% if show.cba_series_id %} {% endif %} - \ No newline at end of file diff --git a/templates/program/show_list.html b/templates/program/show_list.html index 09bfa04..844395d 100644 --- a/templates/program/show_list.html +++ b/templates/program/show_list.html @@ -4,72 +4,69 @@ -
- {% for topic in show_topic_list %} -
+
+{% for topic in showtopic_list %} +
{{ topic.abbrev }} {{ topic }}
- {% endfor %} +{% endfor %}
-
- {% for information in show_information_list %} -
+
+{% for information in showinformation_list %} +
{{ information.abbrev }} {{ information }}
- {% endfor %} +{% endfor %}
-
- {% for focus in music_focus_list %} -
+
+{% for focus in musicfocus_list %} +
{{ focus.abbrev }} {{ focus }}
- {% endfor %} +{% endfor %}
- {% for show in show_list %} +{% for show in show_list %}
- {% for topic in show.show_topic.all %} - {{ topic.abbrev }} - {% endfor %} + {% for topic in show.showtopic.all %} + {{ topic.abbrev }} + {% endfor %} - {% for information in show.show_information.all %} - {{ information.abbrev }} - {% endfor %} + {% for information in show.showinformation.all %} + {{ information.abbrev }} + {% endfor %} - {% for focus in show.music_focus.all %} - {{ focus.abbrev }} - {% endfor %} + {% for focus in show.musicfocus.all %} + {{ focus.abbrev }} + {% endfor %} - {{ show.broadcast_format.abbrev }} + {{ show.broadcastformat.abbrev }}
- -
- {% for slot in show.program_slots.all %} -
{{ slot }}
- {% endfor %} -
-
- {{ show.short_description }} + + + +
+ {% for slot in show.programslots.all %} +
{{ slot }}
+ {% endfor %}
-
- {% endfor %} + +
{{ show.short_description }}
+
+{% endfor %}
-
- {% for format in broadcast_format_list %} -
- {{ format }} -
- {% endfor %} +
+{% for format in broadcastformat_list %} +
{{ format }}
+{% endfor %}
diff --git a/templates/program/timeslot_detail.html b/templates/program/timeslot_detail.html index d589f0e..d8a677e 100644 --- a/templates/program/timeslot_detail.html +++ b/templates/program/timeslot_detail.html @@ -10,25 +10,28 @@
{{ timeslot.show.name }}
- {% for topic in timeslot.show.show_topic.all %} + {% for topic in timeslot.show.showtopic.all %} {{ topic.abbrev }} {% endfor %} - {% for information in timeslot.show.show_information.all %} + + {% for information in timeslot.show.showinformation.all %} {{ information.abbrev }} {% endfor %} - {% for focus in timeslot.show.music_focus.all %} + + {% for focus in timeslot.show.musicfocus.all %} {{ focus.abbrev }} {% endfor %} - {{ timeslot.show.broadcast_format.abbrev }} + + {{ timeslot.show.broadcastformat.abbrev }}
- {% for slot in timeslot.show.program_slots.all %} + {% for slot in timeslot.show.programslots.all %}
{{ slot }}
{% endfor %}
-
{{ timeslot.show.broadcast_format.format }}
+
{{ timeslot.show.broadcastformat.format }}
{% for host in timeslot.show.hosts.all %} @@ -37,6 +40,7 @@
{{ timeslot.show.short_description }}
+
{{ timeslot.show.description }}
-- cgit v0.10.2