changeset 143:1ed461fd2030

Podcast enhancements for #39. Provide channel level keyword support. Provide an alternate download URL so we can support both m4a and mp3 formats.
author Brian Neal <bgneal@gmail.com>
date Sun, 06 Dec 2009 21:28:31 +0000
parents f6904149a233
children 49b713bca29d
files gpp/podcast/models.py gpp/podcast/views.py gpp/templates/podcast/detail.html gpp/templates/podcast/feed.xml
diffstat 4 files changed, 33 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/gpp/podcast/models.py	Sun Dec 06 21:25:00 2009 +0000
+++ b/gpp/podcast/models.py	Sun Dec 06 21:28:31 2009 +0000
@@ -24,6 +24,7 @@
    image = models.ImageField(upload_to='podcast')
    category = models.CharField(max_length=64)
    explicit = models.CharField(max_length=8, choices=EXPLICIT_CHOICES)
+   keywords = models.CharField(max_length=255)
 
    def __unicode__(self):
       return self.title
@@ -37,6 +38,7 @@
    subtitle = models.CharField(max_length=255)
    summary = models.TextField()
    enclosure_url = models.URLField(verify_exists=False)
+   alt_enclosure_url = models.URLField(verify_exists=False, blank=True)
    enclosure_length = models.IntegerField()
    enclosure_type = models.CharField(max_length=32)
    guid = models.CharField(max_length=255)
--- a/gpp/podcast/views.py	Sun Dec 06 21:25:00 2009 +0000
+++ b/gpp/podcast/views.py	Sun Dec 06 21:28:31 2009 +0000
@@ -1,4 +1,6 @@
 """Views for the podcast application"""
+import os.path
+from urlparse import urlparse
 
 from django.shortcuts import render_to_response
 from django.template import RequestContext
@@ -8,6 +10,14 @@
 from podcast.models import Item
 
 
+def get_ext_from_url(url):
+    """
+    This function returns the extension part of the path from the given
+    url.
+    """
+    return os.path.splitext(urlparse(url).path)[1]
+
+
 def index(request):
    try:
       channel = Channel.objects.get(pk=1)
@@ -21,10 +31,18 @@
 
 
 def detail(request, id):
-   podcast = get_object_or_404(Item, pk = id)
+   podcast = get_object_or_404(Item.objects.select_related(), pk = id)
+
+   ext = get_ext_from_url(podcast.enclosure_url)
+   alt_ext = None
+   if podcast.alt_enclosure_url:
+      alt_ext = get_ext_from_url(podcast.alt_enclosure_url)
+
    return render_to_response('podcast/detail.html', {
       'channel': podcast.channel,
       'podcast': podcast, 
+      'ext': ext,
+      'alt_ext': alt_ext,
       },
       context_instance = RequestContext(request))
    
--- a/gpp/templates/podcast/detail.html	Sun Dec 06 21:25:00 2009 +0000
+++ b/gpp/templates/podcast/detail.html	Sun Dec 06 21:28:31 2009 +0000
@@ -7,6 +7,15 @@
 <h3>{{ podcast.pubdate|date:"F d, Y" }} &bull; {{ podcast.title }}</h3>
 <h4>{{ podcast.subtitle }}</h4>
 {{ podcast.summary|linebreaks }}
-<p><a href="{{ podcast.enclosure_url }}">Download Now</a> &bull;
-{{ podcast.enclosure_length|filesizeformat }} &bull; {{ podcast.duration }}</p>
+<ul>
+   <li>
+   <a href="{{ podcast.enclosure_url }}">Download Now ({{ ext }})</a> &bull;
+   {{ podcast.enclosure_length|filesizeformat }} &bull; {{ podcast.duration }}
+   </li>
+   {% if alt_ext %}
+   <li>
+      <a href="{{ podcast.alt_enclosure_url }}">Download Now ({{ alt_ext }})</a>
+   </li>
+   {% endif %}
+</ul>
 {% endblock %}
--- a/gpp/templates/podcast/feed.xml	Sun Dec 06 21:25:00 2009 +0000
+++ b/gpp/templates/podcast/feed.xml	Sun Dec 06 21:28:31 2009 +0000
@@ -13,6 +13,7 @@
 <itunes:author>{{ channel.author }}</itunes:author>
 <itunes:summary>{{ channel.description }}</itunes:summary>
 <description>{{ channel.description }}</description>
+<itunes:keywords>{{ channel.keywords }}</itunes:keywords>
 <itunes:owner>
 <itunes:name>{{ channel.owner_name }}</itunes:name>
 <itunes:email>{{ channel.owner_email }}</itunes:email>