Commit 72d04edf authored by fred's avatar fred

add pre-emission podcasts feed

parent abd2669b
......@@ -14,6 +14,7 @@ urlpatterns = patterns('',
url(r'^grille$', 'panikweb.views.grid', name='grid'),
url(r'^emissions/$', 'panikweb.views.emissions', name='emissions'),
url(r'^emissions/(?P<slug>[\w,-]+)/episodes/$', 'panikweb.views.emissionEpisodes', name='emissionEpisodes'),
url(r'^emissions/(?P<slug>[\w,-]+)/podcasts.rss', 'panikweb.views.emission_podcasts_feed', name='emission-podcasts'),
url(r'^emissions/(?P<slug>[\w,-]+)/chat/$', 'panikweb.views.chat', name='emission-chat'),
url(r'^emissions/(?P<emission_slug>[\w,-]+)/(?P<slug>[\w,-]+)/$', 'panikweb.views.episode', name='episode-view'),
url(r'^emissions/(?P<emission_slug>[\w,-]+)/(?P<slug>[\w,-]+)/$', 'panikweb.views.episode', name='episode-view'),
......
......@@ -659,9 +659,16 @@ 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')
handler.startElement('image', {})
handler.addQuickElement('title', 'Radio Panik')
handler.addQuickElement('url', self.feed['link'] + 'static/img/logo-panik-500.png')
if emission:
handler.addQuickElement('title', emission.title)
else:
handler.addQuickElement('title', 'Radio Panik')
if emission and emission.image and emission.image.url:
handler.addQuickElement('url', emission.image.url)
else:
handler.addQuickElement('url', '/static/img/logo-panik-500.png')
handler.endElement('image')
def root_attributes(self):
......@@ -738,6 +745,60 @@ class AtomNewsFeed(RssNewsFeed):
atom_news_feed = AtomNewsFeed()
class EmissionPodcastsFeed(Feed):
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)
@property
def title(self):
return '%s - Podcasts' % self.emission.title
@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]
def item_title(self, item):
if item.fragment:
return '%s - %s' % (item.title, item.episode.title)
return item.episode.title
def item_link(self, item):
return item.episode.get_absolute_url()
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()]}
emission_podcasts_feed = EmissionPodcastsFeed()
class Party(TemplateView):
template_name = 'party.html'
......
......@@ -49,7 +49,7 @@
{% if episodes.exists or futurEpisodes.exists %}
<h5 class="sectionLabel right"><a class="" href="{% url 'emissionEpisodes' slug=emission.slug %}">Tous ({{ episodes.count }})</a></h5>
<h5 class="sectionLabel">Épisodes</h5>
<h5 class="sectionLabel">Épisodes&nbsp;<a title="Podcasts" class="button icon-rss inBlock" href="{% url 'emission-podcasts' slug=emission.slug%}"></a></h5>
<form method="get" action="{% url 'emissionEpisodes' slug=emission.slug %}" class="" id="search-form">
<input id="id_q" name="q" type="text" {% if search_query %}value="{{ search_query }}"{% endif %}>
<button class="icon-search"></button>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment