Commit 3dc5e1ec authored by fred's avatar fred

change podcast feed to use contrib.syndication

parent 60d49798
from datetime import datetime, timedelta
import time
import math
import os
import stat
import time
from django.views.decorators.cache import cache_control
from django.views.generic.base import TemplateView
......@@ -542,18 +544,40 @@ class NewsItemDetailView(DetailView):
newsitem = NewsItemDetailView.as_view()
class PodcastsFeedView(TemplateView):
template_name = 'podcasts.html'
content_type = 'application/rss+xml'
class PodcastsFeed(Feed):
title = 'Radio Panik - Podcasts'
link = '/'
description_template = 'feed/soundfile.html'
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
def items(self):
return SoundFile.objects.select_related().filter(
podcastable=True).order_by('-creation_timestamp')[:5]
def item_title(self, item):
if item.fragment:
return '%s - %s' % (item.title, item.episode.title)
return item.episode.title
podcasts_feed = PodcastsFeedView.as_view()
def item_link(self, item):
return item.episode.get_absolute_url()
def item_enclosure_url(self, item):
return 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_mimetype(self, item):
return 'audio/mpeg'
def item_pubdate(self, item):
return item.creation_timestamp
podcasts_feed = PodcastsFeed()
class FiberPageView(fiber.views.FiberTemplateView):
......@@ -567,7 +591,7 @@ fiber_page = FiberPageView.as_view()
class RssNewsFeed(Feed):
title = 'Radio Panik'
link = '/news/'
description_template = 'news/feed.html'
description_template = 'feed/newsitem.html'
def items(self):
return NewsItem.objects.order_by('-date')[:10]
......@@ -577,5 +601,4 @@ rss_news_feed = RssNewsFeed()
class AtomNewsFeed(RssNewsFeed):
feed_type = Atom1Feed
atom_news_feed = AtomNewsFeed()
{% load thumbnails %}
{% if obj.episode.image %}
<img src="{{ obj.episode.image|thumbnail:'320x240' }}"/>
{% endif %}
{{ obj.episode.text }}
{% load paniktags %}{% load soundfiles %}<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel>
<title>Radio Panik{% if title %} - {{ title }}{% endif %}</title>
<link>{{ base_url }}</link>
<description></description>
<lastBuildDate>{{ soundfiles.0.creation_timestamp|rfc822 }}</lastBuildDate>
{% for soundfile in soundfiles|slice:":20" %}<item>
<title>{% if soundfile.fragment %}{{ soundfile.title }} - {% endif %}{{ soundfile.episode.title }}</title>
<link>{{ base_url }}{% url 'episode-view' slug=soundfile.episode.slug emission_slug=soundfile.episode.emission.slug %}</link>
<description>{{ soundfile.episode.text|striptags }}</description>
<enclosure url="{{ base_url }}{{ soundfile|format_url:'mp3' }}" length="{{ soundfile|format_length:'mp3' }}" type="audio/mpeg"/>
<guid>{{ base_url }}{{ soundfile.episode.get_absolute_url }}#{{ soundfile.id }}</guid>
<pubDate>{{ soundfile.episode.creation_timestamp|rfc822 }}</pubDate>
</item>
{% endfor %}
</channel>
</rss>
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