From 5b4e0ed7db7e3845cef065d74ad2b2dc3d36e102 Mon Sep 17 00:00:00 2001
From: Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com>
Date: Mon, 28 Dec 2015 17:44:34 +0100
Subject: [PATCH] reformated code.

---
 program/admin.py  |  30 ++++------
 program/models.py | 125 +++++++++++++---------------------------
 program/urls.py   |  65 +++++----------------
 program/views.py  | 141 ++++++++++++++++++++--------------------------
 4 files changed, 125 insertions(+), 236 deletions(-)

diff --git a/program/admin.py b/program/admin.py
index 0fa74613..3086dd5f 100644
--- a/program/admin.py
+++ b/program/admin.py
@@ -1,8 +1,7 @@
 from django.contrib import admin
 from django.utils.translation import ugettext_lazy as _
 
-from models import (BroadcastFormat, MusicFocus, ShowInformation, ShowTopic,
-                    Host, Note, ProgramSlot, Show, TimeSlot)
+from models import BroadcastFormat, MusicFocus, ShowInformation, ShowTopic, Host, Note, ProgramSlot, Show, TimeSlot
 from forms import MusicFocusForm
 
 from datetime import date, datetime, timedelta
@@ -44,12 +43,9 @@ class NoteAdmin(admin.ModelAdmin):
         four_weeks = datetime.now() - timedelta(weeks=4)
         if db_field.name == 'timeslot':
             shows = request.user.shows.all()
-            kwargs['queryset'] = TimeSlot.objects.filter(show__in=shows,
-                                                         start__gt=four_weeks)
+            kwargs['queryset'] = TimeSlot.objects.filter(show__in=shows, start__gt=four_weeks)
 
-        return super(NoteAdmin, self).formfield_for_foreignkey(db_field,
-                                                               request,
-                                                               **kwargs)
+        return super(NoteAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
 
     def save_model(self, request, obj, form, change):
         obj.save()
@@ -62,8 +58,7 @@ class TimeSlotInline(admin.TabularInline):
 class ProgramSlotAdmin(admin.ModelAdmin):
     actions = ('renew',)
     inlines = (TimeSlotInline,)
-    list_display = ('show', 'byweekday', 'rrule', 'tstart', 'tend', 'until',
-                    'timeslot_count')
+    list_display = ('show', 'byweekday', 'rrule', 'tstart', 'tend', 'until', 'timeslot_count')
     list_filter = ('byweekday', 'rrule', 'is_repetition')
     ordering = ('byweekday', 'dstart')
     save_on_top = True
@@ -86,22 +81,17 @@ class ProgramSlotInline(admin.TabularInline):
 
 
 class ShowAdmin(admin.ModelAdmin):
-    filter_horizontal = ('hosts', 'owners', 'musicfocus', 'showinformation',
-                         'showtopic')
+    filter_horizontal = ('hosts', 'owners', 'musicfocus', 'showinformation', 'showtopic')
     inlines = (ProgramSlotInline,)
-    list_display = ('name', 'short_description', 'broadcastformat',
-                    'has_active_programslots')
-    list_filter = ('broadcastformat', 'showinformation', 'showtopic',
-                   'musicfocus',)
+    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')
     fields = (
-        'predecessor', 'broadcastformat', 'name', 'slug', 'image',
-        'image_enabled', 'short_description', 'description',
-        'email',
-        'website', 'cba_series_id', 'automation_id', 'hosts', 'owners',
-        'showinformation', 'showtopic', 'musicfocus',
+        'predecessor', 'broadcastformat', 'name', 'slug', 'image', 'image_enabled', 'short_description', 'description',
+        'email', 'website', 'cba_series_id', 'automation_id', 'hosts', 'owners', 'showinformation', 'showtopic',
+        'musicfocus',
     )
 
 
diff --git a/program/models.py b/program/models.py
index 15417544..8bc0d6b8 100644
--- a/program/models.py
+++ b/program/models.py
@@ -1,7 +1,7 @@
 from django.contrib.auth.models import User
-from django.core.exceptions import (ObjectDoesNotExist, ValidationError,
-                                    MultipleObjectsReturned)
+from django.core.exceptions import ObjectDoesNotExist, ValidationError, MultipleObjectsReturned
 from django.db import models
+from django.db.models import Q
 from django.utils.translation import ugettext_lazy as _
 
 from tinymce import models as tinymce_models
@@ -17,8 +17,7 @@ class BroadcastFormat(models.Model):
     format = models.CharField(_("Format"), max_length=32)
     slug = models.SlugField(_("Slug"), max_length=32, unique=True)
     color = models.CharField(_("Color"), max_length=7, default='#ffffff')
-    text_color = models.CharField(_("Text color"), max_length=7,
-                                  default='#000000')
+    text_color = models.CharField(_("Text color"), max_length=7, default='#000000')
     enabled = models.BooleanField(_("Enabled"), default=True)
 
     class Meta:
@@ -41,12 +40,9 @@ 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)
-    button = models.ImageField(_("Button image"), blank=True, null=True,
-                               upload_to='buttons')
-    button_hover = models.ImageField(_("Button image (hover)"), blank=True,
-                                     null=True, upload_to='buttons')
-    big_button = models.ImageField(_("Big button image"), blank=True,
-                                   null=True, upload_to='buttons')
+    button = models.ImageField(_("Button image"), blank=True, null=True, upload_to='buttons')
+    button_hover = models.ImageField(_("Button image (hover)"), blank=True, null=True, upload_to='buttons')
+    big_button = models.ImageField(_("Big button image"), blank=True, null=True, upload_to='buttons')
 
     class Meta:
         ordering = ('information',)
@@ -101,12 +97,9 @@ 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)
-    button = models.ImageField(_("Button image"), blank=True, null=True,
-                               upload_to='buttons')
-    button_hover = models.ImageField(_("Button image (hover)"), blank=True,
-                                     null=True, upload_to='buttons')
-    big_button = models.ImageField(_("Big button image"), blank=True,
-                                   null=True, upload_to='buttons')
+    button = models.ImageField(_("Button image"), blank=True, null=True, upload_to='buttons')
+    button_hover = models.ImageField(_("Button image (hover)"), blank=True, null=True, upload_to='buttons')
+    big_button = models.ImageField(_("Big button image"), blank=True, null=True, upload_to='buttons')
 
     class Meta:
         ordering = ('topic',)
@@ -161,12 +154,9 @@ 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)
-    button = models.ImageField(_("Button image"), blank=True, null=True,
-                               upload_to='buttons')
-    button_hover = models.ImageField(_("Button image (hover)"), blank=True,
-                                     null=True, upload_to='buttons')
-    big_button = models.ImageField(_("Big button image"), blank=True,
-                                   null=True, upload_to='buttons')
+    button = models.ImageField(_("Button image"), blank=True, null=True, upload_to='buttons')
+    button_hover = models.ImageField(_("Button image (hover)"), blank=True, null=True, upload_to='buttons')
+    big_button = models.ImageField(_("Big button image"), blank=True, null=True, upload_to='buttons')
 
     class Meta:
         ordering = ('focus',)
@@ -237,41 +227,23 @@ class Host(models.Model):
 
 
 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"))
+    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=255)
     slug = models.CharField(_("Slug"), max_length=255, unique=True)
-    image = models.ImageField(_("Image"), blank=True, null=True,
-                              upload_to='show_images')
+    image = models.ImageField(_("Image"), blank=True, null=True, upload_to='show_images')
     image_enabled = models.BooleanField(_("show Image"), default=True)
     short_description = models.CharField(_("Short description"), max_length=64)
-    description = tinymce_models.HTMLField(_("Description"), blank=True,
-                                           null=True)
+    description = tinymce_models.HTMLField(_("Description"), blank=True, null=True)
     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)
-    automation_id = models.IntegerField(_("Automation ID"), blank=True,
-                                        null=True,
-                                        choices=get_automation_id_choices())
+    cba_series_id = models.IntegerField(_("CBA series ID"), blank=True, null=True)
+    automation_id = models.IntegerField(_("Automation ID"), blank=True, null=True, choices=get_automation_id_choices())
     created = models.DateTimeField(auto_now_add=True, editable=False)
     last_updated = models.DateTimeField(auto_now=True, editable=False)
 
@@ -334,19 +306,15 @@ class ProgramSlot(models.Model):
         (5, _("Saturday")),
         (6, _("Sunday")),
     )
-    rrule = models.ForeignKey(RRule, related_name='programslots',
-                              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='programslots',
-                             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"))
     until = models.DateField(_("Last date"))
     is_repetition = models.BooleanField(_("Is repetition"), default=False)
-    automation_id = models.IntegerField(_("Automation ID"), blank=True,
-                                        null=True,
-                                        choices=get_automation_id_choices())
+    automation_id = models.IntegerField(_("Automation ID"), blank=True, null=True, choices=get_automation_id_choices())
     created = models.DateTimeField(auto_now_add=True, editable=False)
     last_updated = models.DateTimeField(auto_now=True, editable=False)
 
@@ -422,15 +390,11 @@ class ProgramSlot(models.Model):
 
         if not old:
             for k in range(min(len(starts), len(ends))):
-                timeslot = TimeSlot.objects.create(programslot=self,
-                                                   start=starts[k],
-                                                   end=ends[k])
+                timeslot = TimeSlot.objects.create(programslot=self, start=starts[k], end=ends[k])
         elif self.until > old.until:
             for k in range(min(len(starts), len(ends))):
                 if starts[k].date() > old.until:
-                    timeslot = TimeSlot.objects.create(programslot=self,
-                                                       start=starts[k],
-                                                       end=ends[k])
+                    timeslot = TimeSlot.objects.create(programslot=self, start=starts[k], end=ends[k])
 
     def timeslot_count(self):
         return self.timeslots.count()
@@ -450,11 +414,9 @@ class ProgramSlot(models.Model):
 class TimeSlotManager(models.Manager):
     def get_or_create_current(self):
         try:
-            return TimeSlot.objects.get(start__lte=datetime.now(),
-                                        end__gt=datetime.now())
+            return TimeSlot.objects.get(start__lte=datetime.now(), end__gt=datetime.now())
         except MultipleObjectsReturned:
-            return TimeSlot.objects.filter(start__lte=datetime.now(),
-                                           end__gt=datetime.now())[0]
+            return TimeSlot.objects.filter(start__lte=datetime.now(), end__gt=datetime.now())[0]
         except ObjectDoesNotExist:
             once = RRule.objects.get(pk=1)
             today = date.today().weekday()
@@ -466,10 +428,8 @@ class TimeSlotManager(models.Manager):
             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 = ProgramSlot(rrule=once, byweekday=today, show=default, dstart=dstart, tstart=tstart, tend=tend, until=until)
+
             try:
                 new_programslot.validate_unique()
                 new_programslot.save()
@@ -482,23 +442,18 @@ class TimeSlotManager(models.Manager):
         today = datetime.combine(day, time(6, 0))
         tomorrow = today + timedelta(days=1)
 
-        return TimeSlot.objects.filter(models.Q(start__lte=today,
-                                                end__gte=today) |
-                                       models.Q(start__gt=today,
-                                                start__lt=tomorrow)).exclude(end=today)
+        return TimeSlot.objects.filter(Q(start__lte=today, end__gte=today) |
+                                       Q(start__gt=today, start__lt=tomorrow)).exclude(end=today)
 
     def get_24h_timeslots(self, start):
         end = start + timedelta(hours=24)
 
-        return TimeSlot.objects.filter(models.Q(start__lte=start,
-                                                end__gte=start) |
-                                       models.Q(start__gt=start,
-                                                start__lt=end)).exclude(end=start)
+        return TimeSlot.objects.filter(Q(start__lte=start, end__gte=start) |
+                                       Q(start__gt=start, start__lt=end)).exclude(end=start)
 
 
 class TimeSlot(models.Model):
-    programslot = models.ForeignKey(ProgramSlot, related_name='timeslots',
-                                    verbose_name=_("Program slot"))
+    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, related_name='timeslots')
@@ -534,10 +489,8 @@ class Note(models.Model):
     timeslot = models.OneToOneField(TimeSlot, verbose_name=_("Time slot"))
     title = models.CharField(_("Title"), max_length=128)
     content = tinymce_models.HTMLField(_("Content"))
-    status = models.IntegerField(_("Status"), choices=STATUS_CHOICES,
-                                 default=1)
-    cba_entry_id = models.IntegerField(_("CBA entry ID"), blank=True,
-                                       null=True)
+    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, related_name='notes')
     created = models.DateTimeField(auto_now_add=True, editable=False)
diff --git a/program/urls.py b/program/urls.py
index 94096ff7..e7217b80 100644
--- a/program/urls.py
+++ b/program/urls.py
@@ -1,65 +1,30 @@
 from django.conf import settings
-from django.conf.urls import patterns, url, include
-from django.db.models import Q
+from django.conf.urls import patterns, url
 from django.views.decorators.cache import cache_page
-from django.views.generic.detail import DetailView
 
-from models import Host, Show, TimeSlot
-from views import current_show, day_schedule, recommendations, show_list, \
-    week_schedule, styles
+from views import current_show, day_schedule, recommendations, show_list, show_detail, timeslot_detail, week_schedule, styles, host_list, host_detail
 
-from datetime import date
+import os
+
+PROGRAM_SITE_MEDIA = os.path.join(os.path.dirname(__file__), '../site_media')
 
-hosts_dict = {
-    'queryset': Host.objects.filter(
-        Q(shows__programslots__until__gte=date.today()) |
-        Q(always_visible=True)).distinct(),
-    'template_object_name': 'host'
-}
-shows_dict = {
-    'queryset': Show.objects.filter(
-        programslots__until__gt=date.today()).exclude(id=1).distinct(),
-    'template_object_name': 'show'
-}
-timeslots_dict = {
-    'queryset': TimeSlot.objects.all(),
-    'template_object_name': 'timeslot'
-}
 recommendations_dict = {'template_name': 'boxes/recommendations.html'}
 
 urlpatterns = patterns('',
                        url(r'^today/?$', day_schedule),
-                       url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/?$',
-                           day_schedule),
-                       url(r'^(?P<year>\d{4})/(?P<week>\d{1,2})/?$',
-                           week_schedule),
-                       url(r'^current_box/?$', cache_page(60)(current_show)),
-                       url(r'^hosts/?$',
-                           DetailView,
-                           dict(hosts_dict, template_name='host_list.html')),
-                       url(r'^hosts/(?P<object_id>\d+)/?$', DetailView,
-                           dict(hosts_dict, template_name='host_detail.html'),
-                           name='host-detail'),
+                       url(r'^week/?$', week_schedule),
+                       url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/?$', day_schedule),
+                       url(r'^(?P<year>\d{4})/(?P<week>\d{1,2})/?$', week_schedule),
+                       url(r'^current_box/?$', cache_page(current_show, 60)),
+                       url(r'^hosts/?$', host_list),
+                       url(r'^hosts/(?P<object_id>\d+)/?$', host_detail, name='host-detail'),
                        url(r'^tips/?$', recommendations),
-                       url(r'^tips_box/?$', recommendations,
-                           recommendations_dict),
+                       url(r'^tips_box/?$', recommendations, recommendations_dict),
                        url(r'^shows/?$', show_list),
-                       url(r'^shows/(?P<slug>[\w-]+)/?$', DetailView,
-                           dict(shows_dict, template_name='show_detail.html'),
-                           name='show-detail'),
-                       url(r'^(?P<object_id>\d+)/?$', DetailView,
-                           dict(timeslots_dict,
-                                template_name='timeslot_detail.html'),
-                           name='timeslot-detail'),
-                       url(r'^week/?$', week_schedule),
+                       url(r'^shows/(?P<slug>[\w-]+)/?$', show_detail, name='show-detail'),
+                       url(r'^(?P<object_id>\d+)/?$', timeslot_detail, name='timeslot-detail'),
                        url(r'^styles.css$', styles))
 
 if settings.DEBUG:
-    import os
-
-    PROGRAM_STATIC_DIR = os.path.join(os.path.dirname(__file__),
-                                      '../site_media')
     urlpatterns += patterns('',
-                            url(r'^static/(?P<path>.*)$',
-                                'django.views.static.serve',
-                                {'document_root': PROGRAM_STATIC_DIR}))
+                            url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': PROGRAM_SITE_MEDIA}))
diff --git a/program/views.py b/program/views.py
index 2305fddc..cba3a250 100644
--- a/program/views.py
+++ b/program/views.py
@@ -3,99 +3,101 @@ import json
 
 from django.views.generic.base import TemplateView
 from django.views.generic.detail import DetailView
+from django.views.generic.list import ListView
 from django.shortcuts import get_object_or_404
 from django.db.models import Q
 from django.http import HttpResponse
 
-from models import (BroadcastFormat, MusicFocus, Note, Show, ShowInformation,
-                    ShowTopic, TimeSlot)
+from models import BroadcastFormat, MusicFocus, Note, Show, ShowInformation, ShowTopic, TimeSlot, Host
+
+
+def host_list(request):
+    queryset = Host.objects.filter(Q(shows__programslots__until__gte=date.today()) |
+                                   Q(always_visible=True)).distinct()
+
+    return ListView.as_view(request, queryset=queryset, template_name='host_list.html')
+
+
+def host_detail(request):
+    queryset = Host.objects.filter(Q(shows__programslots__until__gte=date.today()) |
+                                   Q(always_visible=True)).distinct()
+
+    return DetailView.as_view(request, queryset=queryset, template_name='host_detail.html')
 
 
 def show_list(request):
     queryset = Show.objects.filter(programslots__until__gt=date.today()).exclude(id=1).distinct()
 
     if 'broadcastformat' in request.GET:
-        broadcastformat = get_object_or_404(BroadcastFormat,
-                                            slug=request.GET['broadcastformat'])
-
+        broadcastformat = get_object_or_404(BroadcastFormat, slug=request.GET['broadcastformat'])
         queryset = queryset.filter(broadcastformat=broadcastformat)
     elif 'musicfocus' in request.GET:
-        musicfocus = get_object_or_404(MusicFocus,
-                                       slug=request.GET['musicfocus'])
-
+        musicfocus = get_object_or_404(MusicFocus, slug=request.GET['musicfocus'])
         queryset = queryset.filter(musicfocus=musicfocus)
     elif 'showinformation' in request.GET:
-        showinformation = get_object_or_404(ShowInformation,
-                                            slug=request.GET['showinformation'])
-
+        showinformation = get_object_or_404(ShowInformation, slug=request.GET['showinformation'])
         queryset = queryset.filter(showinformation=showinformation)
     elif 'showtopic' in request.GET:
         showtopic = get_object_or_404(ShowTopic, slug=request.GET['showtopic'])
-
         queryset = queryset.filter(showtopic=showtopic)
 
-    return DetailView(request, queryset=queryset,
-                                   template_object_name='show',
-                                   template_name='show_list.html')
+    return ListView.as_view(request, queryset=queryset, template_object_name='show', template_name='show_list.html')
+
+
+def show_detail(request):
+    queryset = Show.objects.filter(programslots__until__gt=date.today()).exclude(id=1).distinct()
+
+    return DetailView.as_view(request, queryset=queryset, template_name='show_detail.html',)
+
+
+def timeslot_detail(request):
+    queryset = TimeSlot.objects.all()
+
+    return DetailView.as_view(request, queryset=queryset, template_name='timeslot_detail.html')
 
 
 def recommendations(request, template_name='recommendations.html'):
     now = datetime.now()
     end = now + timedelta(weeks=1)
 
-    queryset = TimeSlot.objects.filter(Q(note__isnull=False, note__status=1,
-                                         start__range=(now, end)) |
-                                       Q(show__broadcastformat__slug='sondersendung',
-                                         start__range=(now, end))).order_by('start')[:20]
-    return DetailView(request, queryset=queryset,
-                                   template_name=template_name,
-                                   template_object_name='recommendation')
+    queryset = TimeSlot.objects.filter(Q(note__isnull=False, note__status=1, start__range=(now, end)) |
+                                       Q(show__broadcastformat__slug='sondersendung', start__range=(now, end))).order_by('start')[:20]
+
+    return DetailView.as_view(request, queryset=queryset, template_name=template_name, template_object_name='recommendation')
 
 
 def day_schedule(request, year=None, month=None, day=None):
     if year is None and month is None and day is None:
         today = datetime.combine(date.today(), time(6, 0))
     else:
-        today = datetime.strptime('%s__%s__%s__06__00' % (year, month, day),
-                                  '%Y__%m__%d__%H__%M')
+        today = datetime.strptime('%s__%s__%s__06__00' % (year, month, day), '%Y__%m__%d__%H__%M')
 
     tomorrow = today + timedelta(days=1)
 
-    recommendations = Note.objects.filter(status=1,
-                                          timeslot__start__range=(today,
-                                                                  tomorrow))
+    recommendations = Note.objects.filter(status=1, timeslot__start__range=(today, tomorrow))
 
     default_show = Show.objects.get(pk=1)
 
-    extra_context = dict(day=today, recommendations=recommendations,
-                         default_show=default_show)
+    extra_context = dict(day=today, recommendations=recommendations, default_show=default_show)
 
     timeslots = TimeSlot.objects.get_day_timeslots(today)
 
     if 'broadcastformat' in request.GET:
-        broadcastformat = get_object_or_404(BroadcastFormat,
-                                            slug=request.GET['broadcastformat'])
-
+        broadcastformat = get_object_or_404(BroadcastFormat, slug=request.GET['broadcastformat'])
         extra_context['timeslots'] = timeslots.filter(show__broadcastformat=broadcastformat)
     elif 'musicfocus' in request.GET:
-        musicfocus = get_object_or_404(MusicFocus,
-                                       slug=request.GET['musicfocus'])
-
+        musicfocus = get_object_or_404(MusicFocus, slug=request.GET['musicfocus'])
         extra_context['timeslots'] = timeslots.filter(show__musicfocus=musicfocus)
     elif 'showinformation' in request.GET:
-        showinformation = get_object_or_404(ShowInformation,
-                                            slug=request.GET['showinformation'])
-
+        showinformation = get_object_or_404(ShowInformation, slug=request.GET['showinformation'])
         extra_context['timeslots'] = timeslots.filter(show__showinformation=showinformation)
     elif 'showtopic' in request.GET:
         showtopic = get_object_or_404(ShowTopic, slug=request.GET['showtopic'])
-
         extra_context['showtopic'] = timeslots.filter(show__showtopic=showtopic)
     else:
         extra_context['timeslots'] = timeslots
 
-    return TemplateView(request, extra_context=extra_context,
-                                     template='day_schedule.html')
+    return TemplateView.as_view(request, extra_context=extra_context, template='day_schedule.html')
 
 
 def current_show(request):
@@ -104,18 +106,14 @@ def current_show(request):
     next = current.get_next_by_start()
     after_next = next.get_next_by_start()
 
-    extra_context = dict(current=current,
-                         previous=previous,
-                         next=next,
-                         after_next=after_next)
+    extra_context = dict(current=current, previous=previous, next=next, after_next=after_next)
 
-    return TemplateView(request, template='boxes/current.html',
-                                     extra_context=extra_context)
+    return TemplateView.as_view(request, template='boxes/current.html', extra_context=extra_context)
 
 
 def week_schedule(request, year=None, week=None):
     if year is None and week is None:
-        year, week = datetime.strftime(datetime.now(), '%G__%V').split('__')
+        year, week = datetime.now().strftime('%G__%V').split('__')
 
     monday = tofirstdayinisoweek(int(year), int(week))
     tuesday = monday + timedelta(days=1)
@@ -127,10 +125,8 @@ def week_schedule(request, year=None, week=None):
 
     default_show = Show.objects.get(pk=1)
 
-    extra_context = dict(monday=monday, tuesday=tuesday, wednesday=wednesday,
-                         thursday=thursday, friday=friday,
-                         saturday=saturday, sunday=sunday,
-                         default_show=default_show)
+    extra_context = dict(monday=monday, tuesday=tuesday, wednesday=wednesday,  thursday=thursday, friday=friday,
+                         saturday=saturday, sunday=sunday, default_show=default_show)
 
     extra_context['monday_timeslots'] = TimeSlot.objects.get_day_timeslots(monday)
     extra_context['tuesday_timeslots'] = TimeSlot.objects.get_day_timeslots(tuesday)
@@ -140,20 +136,14 @@ def week_schedule(request, year=None, week=None):
     extra_context['saturday_timeslots'] = TimeSlot.objects.get_day_timeslots(saturday)
     extra_context['sunday_timeslots'] = TimeSlot.objects.get_day_timeslots(sunday)
 
-    extra_context['last_w'] = datetime.strftime(monday - timedelta(days=7),
-                                                '%G/%V')
+    extra_context['last_w'] = datetime.strftime(monday - timedelta(days=7), '%G/%V')
     extra_context['cur_w'] = datetime.strftime(monday, '%G/%V')
-    extra_context['next_w1'] = datetime.strftime(monday + timedelta(days=7),
-                                                 '%G/%V')
-    extra_context['next_w2'] = datetime.strftime(monday + timedelta(days=14),
-                                                 '%G/%V')
-    extra_context['next_w3'] = datetime.strftime(monday + timedelta(days=21),
-                                                 '%G/%V')
-    extra_context['next_w4'] = datetime.strftime(monday + timedelta(days=28),
-                                                 '%G/%V')
+    extra_context['next_w1'] = datetime.strftime(monday + timedelta(days=7), '%G/%V')
+    extra_context['next_w2'] = datetime.strftime(monday + timedelta(days=14), '%G/%V')
+    extra_context['next_w3'] = datetime.strftime(monday + timedelta(days=21), '%G/%V')
+    extra_context['next_w4'] = datetime.strftime(monday + timedelta(days=28), '%G/%V')
 
-    return TemplateView(request, template='week_schedule.html',
-                                     extra_context=extra_context)
+    return TemplateView.as_view(request, template='week_schedule.html', extra_context=extra_context)
 
 
 def styles(request):
@@ -162,36 +152,27 @@ def styles(request):
     extra_context['musicfocus'] = MusicFocus.objects.all()
     extra_context['showinformation'] = ShowInformation.objects.all()
     extra_context['showtopic'] = ShowTopic.objects.all()
-    return TemplateView(request, template='styles.css',
-                                     mimetype='text/css',
-                                     extra_context=extra_context)
+
+    return TemplateView.as_view(request, template='styles.css', mimetype='text/css', extra_context=extra_context)
 
 
 def json_day_schedule(request, year=None, month=None, day=None):
     if year is None and month is None and day is None:
         today = datetime.combine(date.today(), time(0, 0))
     else:
-        today = datetime.strptime('%s__%s__%s__00__00' % (year, month, day),
-                                  '%Y__%m__%d__%H__%M')
+        today = datetime.strptime('%s__%s__%s__00__00' % (year, month, day), '%Y__%m__%d__%H__%M')
 
     timeslots = TimeSlot.objects.get_24h_timeslots(today)
     schedule = []
     for ts in timeslots:
         if ts.programslot.automation_id:
-            schedule.append((ts.start.strftime('%H:%M:%S'),
-                             ts.programslot.show.name,
-                             ts.programslot.automation_id))
+            schedule.append((ts.start.strftime('%H:%M:%S'), ts.programslot.show.name, ts.programslot.automation_id))
         elif ts.programslot.show.automation_id:
-            schedule.append(
-                (ts.start.strftime('%H:%M:%S'), ts.programslot.show.name,
-                 ts.programslot.show.automation_id))
+            schedule.append((ts.start.strftime('%H:%M:%S'), ts.programslot.show.name, ts.programslot.show.automation_id))
         else:
-            schedule.append((ts.start.strftime('%H:%M:%S'),
-                             ts.programslot.show.name, -1))
+            schedule.append((ts.start.strftime('%H:%M:%S'), ts.programslot.show.name, -1))
 
-    return HttpResponse(json.dumps(schedule, ensure_ascii=False,
-                                   encoding='utf8').encode('utf8'),
-                        content_type="application/json; charset=utf-8")
+    return HttpResponse(json.dumps(schedule, ensure_ascii=False, encoding='utf8').encode('utf8'), content_type="application/json; charset=utf-8")
 
 
 def tofirstdayinisoweek(year, week):
-- 
GitLab