]> git.0d.be Git - panikweb.git/blobdiff - panikweb/views.py
feeds: include fragment id in guid
[panikweb.git] / panikweb / views.py
index 706aff00e0e742288bbef060812546cb752407c4..6e5209bbf0707175b5e8d167b126f9d4423fe3e0 100644 (file)
@@ -1,25 +1,41 @@
-from datetime import datetime, timedelta
-import time
+from datetime import datetime, timedelta, date
 import math
+import random
+import os
+import stat
+import time
 
+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
 from django.views.decorators.csrf import csrf_exempt
 from django.views.generic.dates import _date_from_string
+from django.views.generic.dates import MonthArchiveView
 
 from django.core.paginator import Paginator
 
-import fiber.views
+from django.contrib.sites.models import Site
+from django.contrib.syndication.views import Feed, add_domain
+from django.utils.feedgenerator import Atom1Feed, Rss201rev2Feed
+
 from haystack.query import SearchQuerySet
-from jsonresponse import to_json
 
 from emissions.models import Category, Emission, Episode, Diffusion, SoundFile, \
-        Schedule, Nonstop, NewsItem, NewsCategory
+        Schedule, Nonstop, NewsItem, NewsCategory, Focus
 
 from emissions.utils import whatsonair, period_program
 
 from newsletter.forms import SubscribeForm
+from nonstop.utils import get_current_nonstop_track
+from nonstop.models import SomaLogLine
+
+from panikombo.models import ItemTopik
 
 from . import utils
 
@@ -43,9 +59,23 @@ class EmissionMixin:
                         select_params=(False, True),
                         where=['''datetime = (SELECT MIN(datetime)
                                                 FROM emissions_diffusion
-                                               WHERE episode_id = emissions_episode.id)'''],
+                                               WHERE episode_id = emissions_episode.id
+                                                 AND datetime <= CURRENT_TIMESTAMP)'''],
                         tables=['emissions_diffusion'],
-                    ).order_by('-first_diffusion')
+                    ).order_by('-first_diffusion').distinct()
+
+        context['futurEpisodes'] = \
+                episodes_queryset.extra(select={
+                        'first_diffusion': 'emissions_diffusion.datetime',
+                        },
+                        select_params=(False, True),
+                        where=['''datetime = (SELECT MIN(datetime)
+                                                FROM emissions_diffusion
+                                               WHERE episode_id = emissions_episode.id
+                                                 AND datetime > CURRENT_TIMESTAMP)'''],
+                        tables=['emissions_diffusion'],
+                    ).order_by('first_diffusion').distinct()
+
 
         # get all related soundfiles in a single query
         soundfiles = {}
@@ -72,9 +102,24 @@ class EmissionDetailView(DetailView, EmissionMixin):
 
     def get_context_data(self, **kwargs):
         context = super(EmissionDetailView, self).get_context_data(**kwargs)
-        context['sectionName'] = "Emissions"
-        context['schedules'] = Schedule.objects.select_related().filter(emission=self.object).order_by('datetime')
-        context['news'] = NewsItem.objects.all().filter(emission=self.object.id).order_by('-date')[:3]
+        context['schedules'] = Schedule.objects.select_related().filter(
+                emission=self.object).order_by('rerun', 'datetime')
+        context['news'] = NewsItem.objects.all(
+                ).filter(emission=self.object.id
+                ).exclude(expiration_date__lt=date.today()  # expiration date
+                ).exclude(date__lt=date.today() - timedelta(days=60)
+                ).order_by('-date')[:3]
+        try:
+            nonstop_object = Nonstop.objects.get(slug=self.object.slug)
+        except Nonstop.DoesNotExist:
+            pass
+        else:
+            today = date.today()
+            dates = [today - timedelta(days=x) for x in range(7)]
+            if datetime.now().time() < nonstop_object.start:
+                dates = dates[1:]
+            context['nonstop'] = nonstop_object
+            context['nonstop_dates'] = dates
         context.update(self.get_emission_context(self.object))
         return context
 emission = EmissionDetailView.as_view()
@@ -84,28 +129,63 @@ class EpisodeDetailView(DetailView, EmissionMixin):
 
     def get_context_data(self, **kwargs):
         context = super(EpisodeDetailView, self).get_context_data(**kwargs)
-        context['sectionName'] = "Emissions"
-        context['diffusions'] = Diffusion.objects.select_related().filter(episode=self.object.id)
-        context['soundfiles'] = SoundFile.objects.select_related().filter(episode=self.object.id)
-        context['emission'] = Emission.objects.get(slug=self.kwargs.get('emission_slug'))
+        context['diffusions'] = Diffusion.objects.select_related().filter(
+                episode=self.object.id).order_by('datetime')
+        try:
+            context['emission'] = context['episode'].emission
+        except Emission.DoesNotExist:
+            raise Http404()
+        if self.kwargs.get('emission_slug') != context['emission'].slug:
+            raise Http404()
         context.update(self.get_emission_context(context['emission']))
+        context['topiks'] = [x.topik for x in ItemTopik.objects.filter(episode=self.object)]
         return context
 episode = EpisodeDetailView.as_view()
 
 
+class NonstopPlaylistView(TemplateView):
+    template_name = 'nonstop_playlist.html'
+
+    def get_context_data(self, **kwargs):
+        context = super(NonstopPlaylistView, self).get_context_data(**kwargs)
+        try:
+            context['emission'] = Emission.objects.get(slug=kwargs.get('slug'))
+        except Emission.DoesNotExist:
+            raise Http404()
+        context['date'] = date(int(kwargs.get('year')),
+                int(kwargs.get('month')), int(kwargs.get('day')))
+        context['future'] = (context['date'] >= date.today())
+
+        nonstop_object = Nonstop.objects.get(slug=kwargs.get('slug'))
+        start = datetime(
+                int(kwargs.get('year')), int(kwargs.get('month')), int(kwargs.get('day')),
+                nonstop_object.start.hour, nonstop_object.start.minute)
+        end = datetime(
+                int(kwargs.get('year')), int(kwargs.get('month')), int(kwargs.get('day')),
+                nonstop_object.end.hour, nonstop_object.end.minute)
+        if end < start:
+            end = end + timedelta(days=1)
+        context['tracks'] = SomaLogLine.objects.filter(
+                play_timestamp__gte=start,
+                play_timestamp__lte=end,
+                on_air=True).select_related()
+        return context
+
+nonstop_playlist = NonstopPlaylistView.as_view()
+
 class EmissionEpisodesDetailView(DetailView, EmissionMixin):
     model = Emission
     template_name = 'emissions/episodes.html'
 
     def get_context_data(self, **kwargs):
         context = super(EmissionEpisodesDetailView, self).get_context_data(**kwargs)
-        context['sectionName'] = "Emissions"
-        context['schedules'] = Schedule.objects.select_related().filter(emission=self.object).order_by('datetime')
+        context['schedules'] = Schedule.objects.select_related().filter(
+                emission=self.object).order_by('rerun', 'datetime')
 
         context['search_query'] = self.request.GET.get('q')
         if context['search_query']:
             # query string
-            sqs = SearchQuerySet().filter(django_ct='emissions.episode',
+            sqs = SearchQuerySet().models(Episode).filter(
                     emission_slug_exact=self.object.slug, text=context['search_query'])
             episode_ids = [x.pk for x in sqs]
         else:
@@ -115,12 +195,43 @@ class EmissionEpisodesDetailView(DetailView, EmissionMixin):
         return context
 emissionEpisodes = EmissionEpisodesDetailView.as_view()
 
+
+class SoundFileEmbedView(DetailView):
+    model = SoundFile
+    template_name = 'soundfiles/embed.html'
+
+    def get_context_data(self, **kwargs):
+        context = super(SoundFileEmbedView, self).get_context_data(**kwargs)
+        if self.kwargs.get('episode_slug') != self.object.episode.slug:
+            raise Http404()
+        if self.kwargs.get('emission_slug') != self.object.episode.emission.slug:
+            raise Http404()
+        context['episode'] = self.object.episode
+        return context
+soundfile_embed = SoundFileEmbedView.as_view()
+
+
+class SoundFileDialogEmbedView(DetailView):
+    model = SoundFile
+    template_name = 'soundfiles/dialog-embed.html'
+
+    def get_context_data(self, **kwargs):
+        context = super(SoundFileDialogEmbedView, self).get_context_data(**kwargs)
+        if self.kwargs.get('episode_slug') != self.object.episode.slug:
+            raise Http404()
+        if self.kwargs.get('emission_slug') != self.object.episode.emission.slug:
+            raise Http404()
+        context['episode'] = self.object.episode
+        return context
+soundfile_dlg_embed = SoundFileDialogEmbedView.as_view()
+
+
+
 class ProgramView(TemplateView):
     template_name = 'program.html'
 
     def get_context_data(self, year=None, week=None, **kwargs):
         context = super(ProgramView, self).get_context_data(**kwargs)
-        context['sectionName'] = "Emissions"
 
         context['weekday'] = datetime.today().weekday()
 
@@ -129,18 +240,11 @@ class ProgramView(TemplateView):
         context['week_first_day'] = utils.tofirstdayinisoweek(year, week)
         context['week_last_day'] = context['week_first_day'] + timedelta(days=6)
 
-        previous_week = context['week_first_day'] - timedelta(days=7)
-        context['previous_week_no'] = previous_week.isocalendar()[1]
-        context['previous_week_year'] = previous_week.isocalendar()[0]
-
-        next_week = context['week_first_day'] + timedelta(days=7)
-        context['next_week_no'] = next_week.isocalendar()[1]
-        context['next_week_year'] = next_week.isocalendar()[0]
-
         return context
 
 program = ProgramView.as_view()
 
+@python_2_unicode_compatible
 class TimeCell:
     nonstop = None
     w = 1
@@ -162,14 +266,17 @@ class TimeCell:
                 end_time.minute)
         self.schedules.append(schedule)
 
-    def __unicode__(self):
+    def sorted_schedules(self):
+        return sorted(self.schedules, key=lambda x: x.week_sort_key())
+
+    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):
@@ -177,7 +284,6 @@ class Grid(TemplateView):
 
     def get_context_data(self, **kwargs):
         context = super(Grid, self).get_context_data(**kwargs)
-        context['sectionName'] = "Emissions"
 
         nb_lines = 2 * 24 # the cells are half hours
         grid = []
@@ -188,18 +294,20 @@ class Grid(TemplateView):
 
         nonstops = []
         for nonstop in Nonstop.objects.all():
+            if nonstop.start == nonstop.end:
+                continue
             if nonstop.start < nonstop.end:
                 nonstops.append([nonstop.start.hour + nonstop.start.minute/60.,
                                  nonstop.end.hour + nonstop.end.minute/60.,
-                                 nonstop.title, nonstop.slug])
+                                 nonstop.title, nonstop.slug, nonstop])
             else:
                 # crossing midnight
                 nonstops.append([nonstop.start.hour + nonstop.start.minute/60.,
                                  24,
-                                 nonstop.title, nonstop.slug])
+                                 nonstop.title, nonstop.slug, nonstop])
                 nonstops.append([0,
                                  nonstop.end.hour + nonstop.end.minute/60.,
-                                 nonstop.title, nonstop.slug])
+                                 nonstop.title, nonstop.slug, nonstop])
         nonstops.sort()
 
         for i in range(nb_lines):
@@ -211,6 +319,7 @@ class Grid(TemplateView):
             for time_cell in grid[-1]:
                 time_cell.nonstop = nonstop[2]
                 time_cell.nonstop_slug = nonstop[3]
+                time_cell.redirect_path = nonstop[4].redirect_path
                 if nonstop[1] == 5:
                     # the one ending at 5am will be cut down, so we inscribe
                     # its duration manually
@@ -250,7 +359,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(
@@ -356,8 +465,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:
@@ -403,16 +511,8 @@ class Home(TemplateView):
 
     def get_context_data(self, **kwargs):
         context = super(Home, self).get_context_data(**kwargs)
-        context['sectionName'] = "Home"
-        context['focus'] = NewsItem.objects.select_related('category').filter(focus=True).exclude(image__isnull=True).exclude(image__exact='').order_by('-date')[:9]
-        context['emissions'] = Emission.objects.filter(archived=False,
-                creation_timestamp__gte=datetime(2013, 9, 13)).order_by('title')
-        schedules = Schedule.objects.select_related().order_by('datetime')
-        days = []
-        for day in range(7):
-            days.append({'schedules': [x for x in schedules if x.is_on_weekday(day+1)],
-                         'datetime': datetime(2007, 1, day+1)})
-        context['days'] = days
+        context['emissions'] = Emission.objects.filter(archived=False).order_by('-creation_timestamp')[:3]
+        context['newsitems'] = NewsItem.objects.exclude(date__gt=date.today()).order_by('-date')[:3]
 
         context['soundfiles'] = SoundFile.objects.prefetch_related('episode__emission__categories').filter(
                 podcastable=True, fragment=False) \
@@ -422,7 +522,7 @@ class Home(TemplateView):
                     where=['''datetime = (SELECT MIN(datetime)
                                             FROM emissions_diffusion
                                         WHERE episode_id = emissions_episode.id)'''],
-                    tables=['emissions_diffusion'],).order_by('-first_diffusion') [:6]
+                    tables=['emissions_diffusion'],).order_by('-creation_timestamp').distinct() [:3]
 
         context['newsletter_form'] = SubscribeForm()
 
@@ -434,9 +534,9 @@ class NewsItemView(DetailView):
     model = NewsItem
     def get_context_data(self, **kwargs):
         context = super(NewsItemView, self).get_context_data(**kwargs)
-        context['sectionName'] = "News"
-        context['focus'] = list(NewsItem.objects.select_related('category').filter(focus=True).exclude(image__isnull=True).exclude(image__exact='').order_by('-date')[0:9])
         context['categories'] = NewsCategory.objects.all()
+        context['news'] = NewsItem.objects.all().order_by('-date')
+        context['topiks'] = [x.topik for x in ItemTopik.objects.filter(newsitem=self.object)]
         return context
 newsitemview = NewsItemView.as_view()
 
@@ -444,40 +544,50 @@ class News(TemplateView):
     template_name = 'news.html'
     def get_context_data(self, **kwargs):
         context = super(News, self).get_context_data(**kwargs)
-        context['sectionName'] = "News"
-        context['focus'] = NewsItem.objects.select_related('category').filter(focus=True).exclude(image__isnull=True).exclude(image__exact='').order_by('-date')[:9]
-        context['news'] = NewsItem.objects.all().exclude(focus=True).exclude(image__isnull=True).exclude(image__exact='').order_by('-date')[3:14]
+        context['focus'] = NewsItem.objects.exclude(date__gt=date.today()  # publication date
+                ).exclude(expiration_date__lt=date.today()  # expiration date
+                ).filter(got_focus__isnull=False
+                ).select_related('category').order_by('-date')[:10]
+        context['news'] = NewsItem.objects.exclude(date__gt=date.today()).order_by('-date')
         return context
 
 news = News.as_view()
 
-class NewsArchives(TemplateView):
-    template_name = 'news/archives.html'
+
+class Agenda(TemplateView):
+    template_name = 'agenda.html'
     def get_context_data(self, **kwargs):
-        context = super(NewsArchives, self).get_context_data(**kwargs)
-        context['sectionName'] = "News"
-        context['search_query'] = self.request.GET.get('q')
-        sqs = SearchQuerySet().filter(django_ct='emissions.newsitem')
-        if context['search_query']:
-            # query string
-            sqs = sqs.filter(text=context['search_query'])
-        else:
-            sqs = sqs.order_by('-date')
+        context = super(Agenda, self).get_context_data(**kwargs)
+        context['agenda'] = NewsItem.objects.exclude(date__gt=date.today()).filter(
+                event_date__gte=date.today()).order_by('date')[:20]
+        context['news'] = NewsItem.objects.exclude(date__gt=date.today()).order_by('-date')
+        context['previous_month'] = datetime.today().replace(day=1) - timedelta(days=2)
+        return context
+
+agenda = Agenda.as_view()
 
-        sqs = sqs.load_all()
 
-        context['results'] = sqs
+class AgendaByMonth(MonthArchiveView):
+    template_name = 'agenda.html'
+    queryset = NewsItem.objects.filter(event_date__isnull=False)
+    allow_future = True
+    date_field = 'event_date'
+    month_format = '%m'
 
+    def get_context_data(self, **kwargs):
+        context = super(AgendaByMonth, self).get_context_data(**kwargs)
+        context['agenda'] = context['object_list']
+        context['news'] = NewsItem.objects.all().order_by('-date')
         return context
 
-newsArchives = NewsArchives.as_view()
+agenda_by_month = AgendaByMonth.as_view()
+
 
 class Emissions(TemplateView):
     template_name = 'emissions.html'
 
     def get_context_data(self, **kwargs):
         context = super(Emissions, self).get_context_data(**kwargs)
-        context['sectionName'] = "Emissions"
         context['emissions'] = Emission.objects.prefetch_related('categories').filter(archived=False).order_by('title')
         context['categories'] = Category.objects.all()
         return context
@@ -489,8 +599,8 @@ class EmissionsArchives(TemplateView):
 
     def get_context_data(self, **kwargs):
         context = super(EmissionsArchives, self).get_context_data(**kwargs)
-        context['sectionName'] = "Emissions"
         context['emissions'] = Emission.objects.prefetch_related('categories').filter(archived=True).order_by('title')
+        context['categories'] = Category.objects.all()
         return context
 emissionsArchives = EmissionsArchives.as_view()
 
@@ -500,26 +610,32 @@ class Listen(TemplateView):
 
     def get_context_data(self, **kwargs):
         context = super(Listen, self).get_context_data(**kwargs)
-        context['sectionName'] = "Listen"
+        context['focus'] = SoundFile.objects.prefetch_related('episode__emission__categories').filter(
+                podcastable=True, got_focus__isnull=False) \
+                .select_related().extra(select={
+                    'first_diffusion': 'emissions_diffusion.datetime', },
+                    select_params=(False, True),
+                    where=['''datetime = (SELECT MIN(datetime)
+                                            FROM emissions_diffusion
+                                        WHERE episode_id = emissions_episode.id)'''],
+                    tables=['emissions_diffusion'],).order_by('-first_diffusion').distinct() [:10]
         context['soundfiles'] = SoundFile.objects.prefetch_related('episode__emission__categories').filter(
-                podcastable=True, fragment=False) \
+                podcastable=True) \
                 .select_related().extra(select={
                     'first_diffusion': 'emissions_diffusion.datetime', },
                     select_params=(False, True),
                     where=['''datetime = (SELECT MIN(datetime)
                                             FROM emissions_diffusion
                                         WHERE episode_id = emissions_episode.id)'''],
-                    tables=['emissions_diffusion'],).order_by('-first_diffusion') [:10]
+                    tables=['emissions_diffusion'],).order_by('-creation_timestamp').distinct()
 
-        context['categories'] = Category.objects.all()
 
         return context
 
 listen = Listen.as_view()
 
-@cache_control(max_age=25)
+@cache_control(max_age=15)
 @csrf_exempt
-@to_json('api')
 def onair(request):
     d = whatsonair()
     if d.get('episode'):
@@ -528,17 +644,25 @@ def onair(request):
             'url': d['episode'].get_absolute_url()
         }
     if d.get('emission'):
+        chat_url = None
+        if d['emission'].chat_open:
+            chat_url = reverse('emission-chat', kwargs={'slug': d['emission'].slug})
         d['emission'] = {
             'title': d['emission'].title,
-            'url': d['emission'].get_absolute_url()
+            'url': d['emission'].get_absolute_url(),
+            'chat': chat_url,
         }
     if d.get('nonstop'):
+        redirect_path = d['nonstop'].redirect_path
         d['nonstop'] = {
             'title': d['nonstop'].title,
         }
+        if redirect_path:
+            d['nonstop']['url'] = redirect_path
+        d.update(get_current_nonstop_track())
     if d.get('current_slot'):
         del d['current_slot']
-    return d
+    return JsonResponse({'data': d})
 
 
 class NewsItemDetailView(DetailView):
@@ -546,24 +670,206 @@ class NewsItemDetailView(DetailView):
 
 newsitem = NewsItemDetailView.as_view()
 
+class RssCustomPodcastsFeed(Rss201rev2Feed):
+    def add_root_elements(self, handler):
+        super(RssCustomPodcastsFeed, self).add_root_elements(handler)
+        emission = self.feed.get('emission')
+        if emission and emission.image and emission.image.url:
+            image_url = emission.image.url
+        else:
+            image_url = '/static/img/logo-panik-500.png'
+        image_url = urlparse.urljoin(self.feed['link'], image_url)
+        handler.startElement('image', {})
+        if emission:
+            handler.addQuickElement('title', emission.title)
+        else:
+            handler.addQuickElement('title', settings.RADIO_NAME)
+        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:
+            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', settings.RADIO_NAME)
+            handler.startElement('itunes:owner', {})
+            handler.addQuickElement('itunes:email', 'info@radiopanik.org')
+            handler.addQuickElement('itunes:name', settings.RADIO_NAME)
+            handler.endElement('itunes:owner')
+
+    def root_attributes(self):
+        attrs = super(RssCustomPodcastsFeed, self).root_attributes()
+        attrs['xmlns:dc'] = 'http://purl.org/dc/elements/1.1/'
+        attrs['xmlns:itunes'] = 'http://www.itunes.com/dtds/podcast-1.0.dtd'
+        return attrs
+
+    def add_item_elements(self, handler, item):
+        super(RssCustomPodcastsFeed, self).add_item_elements(handler, item)
+        explicit = 'no'
+        for tag in item.get('tags') or []:
+            handler.addQuickElement('dc:subject', tag)
+            if tag == 'explicit':
+                explicit = 'yes'
+        if item.get('tags'):
+            handler.addQuickElement('itunes:keywords', ','.join(item.get('tags')))
+        handler.addQuickElement('itunes:explicit', explicit)
+        episode = item.get('episode')
+        if episode and episode.image and episode.image.url:
+            image_url = urlparse.urljoin(self.feed['link'], episode.image.url)
+            handler.addQuickElement('itunes:image', None, {'href': image_url})
+        soundfile = item.get('soundfile')
+        if soundfile.duration:
+            handler.addQuickElement('itunes:duration', '%02d:%02d:%02d' % (
+                soundfile.duration / 3600,
+                soundfile.duration % 3600 / 60,
+                soundfile.duration % 60))
+
+
+class PodcastsFeed(Feed):
+    title = '%s - Podcasts' % settings.RADIO_NAME
+    link = '/'
+    description_template = 'feed/soundfile.html'
+    feed_type = RssCustomPodcastsFeed
+
+    def items(self):
+        return SoundFile.objects.select_related().filter(
+                podcastable=True).order_by('-creation_timestamp')[:20]
+
+    def item_title(self, item):
+        if item.fragment:
+            return '[%s] %s - %s' % (item.episode.emission.title, item.title, item.episode.title)
+        return '[%s] %s' % (item.episode.emission.title, item.episode.title)
+
+    def item_link(self, item):
+        if item.fragment:
+            return item.episode.get_absolute_url() + '#%s' % item.id
+        return item.episode.get_absolute_url() + '#%s' % item.id
+
+    def item_enclosure_url(self, item):
+        current_site = Site.objects.get(id=settings.SITE_ID)
+        return add_domain(current_site.domain, item.get_format_url('mp3'))
+
+    def item_enclosure_length(self, item):
+        sound_path = item.get_format_path('mp3')
+        try:
+            return os.stat(sound_path)[stat.ST_SIZE]
+        except OSError:
+            return 0
+
+    def item_enclosure_mime_type(self, item):
+        return 'audio/mpeg'
+
+    def item_pubdate(self, item):
+        return item.creation_timestamp
+
+    def item_extra_kwargs(self, item):
+        return {'tags': [x.name for x in item.episode.tags.all()],
+                'soundfile': item,
+                'episode': item.episode}
+
+podcasts_feed = PodcastsFeed()
+
+
+class RssNewsFeed(Feed):
+    title = settings.RADIO_NAME
+    link = '/news/'
+    description_template = 'feed/newsitem.html'
+
+    def items(self):
+        return NewsItem.objects.order_by('-date')[:20]
+
+rss_news_feed = RssNewsFeed()
+
+class Atom1FeedWithBaseXml(Atom1Feed):
+    def root_attributes(self):
+        root_attributes = super(Atom1FeedWithBaseXml, self).root_attributes()
+        scheme, netloc, path, params, query, fragment  = urlparse.urlparse(self.feed['feed_url'])
+        root_attributes['xml:base'] = urlparse.urlunparse((scheme, netloc, '/', params, query, fragment))
+        return root_attributes
+
+class AtomNewsFeed(RssNewsFeed):
+    feed_type = Atom1FeedWithBaseXml
+
+atom_news_feed = AtomNewsFeed()
+
+
+class EmissionPodcastsFeed(PodcastsFeed):
+    description_template = 'feed/soundfile.html'
+    feed_type = RssCustomPodcastsFeed
+
+    def __call__(self, request, *args, **kwargs):
+        self.emission = Emission.objects.get(slug=kwargs.get('slug'))
+        return super(EmissionPodcastsFeed, self).__call__(request, *args, **kwargs)
+
+    def item_title(self, item):
+        if item.fragment:
+            return '%s - %s' % (item.title, item.episode.title)
+        return item.episode.title
 
-class PodcastsFeedView(TemplateView):
-    template_name = 'podcasts.html'
-    content_type = 'application/rss+xml'
+    @property
+    def title(self):
+        return self.emission.title
 
-    def get_context_data(self, **kwargs):
-        context = super(PodcastsFeedView, self).get_context_data(**kwargs)
-        context['base_url'] = self.request.build_absolute_uri('/')[:-1]
-        context['soundfiles'] = SoundFile.objects.select_related().filter(
-                podcastable=True).order_by('-creation_timestamp')
-        return context
+    @property
+    def description(self):
+        return self.emission.subtitle
+
+    @property
+    def link(self):
+        return reverse('emission-view', kwargs={'slug': self.emission.slug})
+
+    def feed_extra_kwargs(self, obj):
+        return {'emission': self.emission}
+
+    def items(self):
+        return SoundFile.objects.select_related().filter(
+                podcastable=True,
+                episode__emission__slug=self.emission.slug).order_by('-creation_timestamp')[:20]
 
-podcasts_feed = PodcastsFeedView.as_view()
+emission_podcasts_feed = EmissionPodcastsFeed()
 
 
-class FiberPageView(fiber.views.FiberTemplateView):
+class Party(TemplateView):
+    template_name = 'party.html'
+
     def get_context_data(self, **kwargs):
-        context = super(FiberPageView, self).get_context_data(**kwargs)
-        context['sectionName'] = 'About'
+        context = super(Party, self).get_context_data(**kwargs)
+        t = random.choice(['newsitem']*2 + ['emission']*3 + ['soundfile']*1 + ['episode']*2)
+        focus = Focus()
+        if t == 'newsitem':
+            focus.newsitem = NewsItem.objects.exclude(
+                    image__isnull=True).exclude(image__exact='').order_by('?')[0]
+        elif t == 'emission':
+            focus.emission = Emission.objects.exclude(
+                    image__isnull=True).exclude(image__exact='').order_by('?')[0]
+        elif t == 'episode':
+            focus.episode = Episode.objects.exclude(
+                    image__isnull=True).exclude(image__exact='').order_by('?')[0]
+        elif t == 'soundfile':
+            focus.soundfile = SoundFile.objects.exclude(
+                    episode__image__isnull=True).exclude(episode__image__exact='').order_by('?')[0]
+
+        context['focus'] = focus
+
         return context
-fiber_page = FiberPageView.as_view()
+
+party = Party.as_view()
+
+
+
+class Chat(DetailView, EmissionMixin):
+    model = Emission
+    template_name = 'chat.html'
+
+chat = cache_control(max_age=15)(Chat.as_view())