Mercurial > public > sg101
comparison 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 |
comparison
equal
deleted
inserted
replaced
142:f6904149a233 | 143:1ed461fd2030 |
---|---|
1 """Views for the podcast application""" | 1 """Views for the podcast application""" |
2 import os.path | |
3 from urlparse import urlparse | |
2 | 4 |
3 from django.shortcuts import render_to_response | 5 from django.shortcuts import render_to_response |
4 from django.template import RequestContext | 6 from django.template import RequestContext |
5 from django.shortcuts import get_object_or_404 | 7 from django.shortcuts import get_object_or_404 |
6 | 8 |
7 from podcast.models import Channel | 9 from podcast.models import Channel |
8 from podcast.models import Item | 10 from podcast.models import Item |
11 | |
12 | |
13 def get_ext_from_url(url): | |
14 """ | |
15 This function returns the extension part of the path from the given | |
16 url. | |
17 """ | |
18 return os.path.splitext(urlparse(url).path)[1] | |
9 | 19 |
10 | 20 |
11 def index(request): | 21 def index(request): |
12 try: | 22 try: |
13 channel = Channel.objects.get(pk=1) | 23 channel = Channel.objects.get(pk=1) |
19 }, | 29 }, |
20 context_instance = RequestContext(request)) | 30 context_instance = RequestContext(request)) |
21 | 31 |
22 | 32 |
23 def detail(request, id): | 33 def detail(request, id): |
24 podcast = get_object_or_404(Item, pk = id) | 34 podcast = get_object_or_404(Item.objects.select_related(), pk = id) |
35 | |
36 ext = get_ext_from_url(podcast.enclosure_url) | |
37 alt_ext = None | |
38 if podcast.alt_enclosure_url: | |
39 alt_ext = get_ext_from_url(podcast.alt_enclosure_url) | |
40 | |
25 return render_to_response('podcast/detail.html', { | 41 return render_to_response('podcast/detail.html', { |
26 'channel': podcast.channel, | 42 'channel': podcast.channel, |
27 'podcast': podcast, | 43 'podcast': podcast, |
44 'ext': ext, | |
45 'alt_ext': alt_ext, | |
28 }, | 46 }, |
29 context_instance = RequestContext(request)) | 47 context_instance = RequestContext(request)) |
30 | 48 |
31 | 49 |
32 def feed(request): | 50 def feed(request): |