]> git.0d.be Git - panikweb.git/blobdiff - panikweb/views.py
templates: strip label of embed dialog
[panikweb.git] / panikweb / views.py
index 54bbec2e337a9bca276ff300e05190acf92d5dd3..f918932890c383817649aeb3513441ffb830cf8e 100644 (file)
@@ -6,11 +6,13 @@ import random
 import os
 import stat
 import time
-import urlparse
 
 from django.core.urlresolvers import reverse
 from django.conf import settings
 from django.http import Http404, JsonResponse
+from django.utils.encoding import force_text
+from django.utils.encoding import python_2_unicode_compatible
+from django.utils.six.moves.urllib import parse as urlparse
 from django.views.decorators.cache import cache_control
 from django.views.generic.base import TemplateView
 from django.views.generic.detail import DetailView
@@ -262,6 +264,7 @@ class ProgramView(TemplateView):
 
 program = ProgramView.as_view()
 
+@python_2_unicode_compatible
 class TimeCell:
     nonstop = None
     w = 1
@@ -283,14 +286,14 @@ class TimeCell:
                 end_time.minute)
         self.schedules.append(schedule)
 
-    def __unicode__(self):
+    def __str__(self):
         if self.schedules:
             return ', '.join([x.emission.title for x in self.schedules])
         else:
             return self.nonstop
 
     def __eq__(self, other):
-        return (unicode(self) == unicode(other) and self.time_label == other.time_label)
+        return (force_text(self) == force_text(other) and self.time_label == other.time_label)
 
 
 class Grid(TemplateView):
@@ -377,7 +380,7 @@ class Grid(TemplateView):
                             continue
                         # here it is, same cell, same emission, several
                         # schedules
-                        schedule_list.sort(lambda x,y: cmp(x.get_duration(), y.get_duration()))
+                        schedule_list.sort(key=lambda x: x.get_duration())
 
                         schedule = schedule_list[0]
                         end_time = schedule.datetime + timedelta(
@@ -483,8 +486,7 @@ class Grid(TemplateView):
                                     grid[i][j].time_label = same_cell_below.time_label
                                     # then we sort emissions so the longest are
                                     # put first
-                                    grid[i][j].schedules.sort(
-                                            lambda x, y: -cmp(x.get_duration(), y.get_duration()))
+                                    grid[i][j].schedules.sort(key=lambda x: -x.get_duration())
                                     # then we add individual time labels to the
                                     # other schedules
                                     for schedule in current_cell_schedules:
@@ -663,7 +665,7 @@ def onair(request):
             title = 'Le festival arrive, découvrez déjà la musique !'
         d = {'title': 'XXX', 'nonstop': FakeNonstop()}
         #return JsonResponse({'data': {'emission': {'title': 'À partir du 31 juillet 18h', 'url': '/'}}})
-    elif date.today() > date(2019, 8, 5):
+    elif date.today() >= date(2019, 8, 5):
         return JsonResponse({'data': {'emission': {'title': "À l'année prochaine, découvrez les podcasts !", 'url': '/'}}})
     else:
         d = whatsonair()
@@ -681,13 +683,27 @@ def onair(request):
             'url': d['emission'].get_absolute_url(),
             'chat': chat_url,
         }
+
+    track_title = None
+    playing_txt = os.path.join(settings.MEDIA_ROOT, 'playing.txt')
+    if os.path.exists(playing_txt):
+        track_title = open(playing_txt).read().strip()
+        if len(track_title) < 6:
+            track_title = None
     if d.get('nonstop'):
         d['nonstop'] = {
             'title': d['nonstop'].title,
         }
-        playing_txt = os.path.join(settings.MEDIA_ROOT, 'playing.txt')
-        if os.path.exists(playing_txt):
-            d['track_title'] = open(playing_txt).read().strip()
+        if track_title:
+            d['track_title'] = track_title
+    elif d.get('emission') and not d.get('episode') and track_title:
+        # live emission, if there's a track playing, and no known episode,
+        # display it.
+        d['episode'] = {
+            'title': track_title,
+            'url': d['emission']['url'],
+        }
+
     if d.get('current_slot'):
         del d['current_slot']
     return JsonResponse({'data': d})
@@ -714,9 +730,27 @@ class RssCustomPodcastsFeed(Rss201rev2Feed):
             handler.addQuickElement('title', 'Radio Esperanzah!')
         handler.addQuickElement('url', image_url)
         handler.endElement('image')
+        handler.addQuickElement('itunes:explicit', 'no')  # invidividual items will get their own value
         handler.addQuickElement('itunes:image', None, {'href': image_url})
-        if emission and emission.subtitle:
-            handler.addQuickElement('itunes:subtitle', emission.subtitle)
+        if emission:
+            if emission.subtitle:
+                handler.addQuickElement('itunes:subtitle', emission.subtitle)
+            for category in emission.categories.all():
+                if category.itunes_category:
+                    handler.addQuickElement('itunes:category', None, {'text': category.itunes_category})
+
+            handler.addQuickElement('itunes:author', emission.title)
+            handler.startElement('itunes:owner', {})
+            if emission.email:
+                handler.addQuickElement('itunes:email', emission.email)
+            handler.addQuickElement('itunes:name', emission.title)
+            handler.endElement('itunes:owner')
+        else:
+            handler.addQuickElement('itunes:author', 'Radio Esperanzah!')
+            handler.startElement('itunes:owner', {})
+            handler.addQuickElement('itunes:email', 'radio@esperanzah.be')
+            handler.addQuickElement('itunes:name', 'Radio Esperanzah!')
+            handler.endElement('itunes:owner')
 
     def root_attributes(self):
         attrs = super(RssCustomPodcastsFeed, self).root_attributes()