Mercurial > public > sg101
diff gpp/podcast/views.py @ 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 | dbd703f7d63a |
children | 9175392da056 |
line wrap: on
line diff
--- 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))