annotate gpp/podcast/views.py @ 227:423c39ee44e0

Rework the who's online middleware and template tag for #87.
author Brian Neal <bgneal@gmail.com>
date Tue, 06 Jul 2010 03:02:20 +0000
parents 1ed461fd2030
children 9175392da056
rev   line source
gremmie@1 1 """Views for the podcast application"""
bgneal@143 2 import os.path
bgneal@143 3 from urlparse import urlparse
gremmie@1 4
gremmie@1 5 from django.shortcuts import render_to_response
gremmie@1 6 from django.template import RequestContext
gremmie@1 7 from django.shortcuts import get_object_or_404
gremmie@1 8
gremmie@1 9 from podcast.models import Channel
gremmie@1 10 from podcast.models import Item
gremmie@1 11
gremmie@1 12
bgneal@143 13 def get_ext_from_url(url):
bgneal@143 14 """
bgneal@143 15 This function returns the extension part of the path from the given
bgneal@143 16 url.
bgneal@143 17 """
bgneal@143 18 return os.path.splitext(urlparse(url).path)[1]
bgneal@143 19
bgneal@143 20
gremmie@1 21 def index(request):
gremmie@1 22 try:
gremmie@1 23 channel = Channel.objects.get(pk=1)
gremmie@1 24 except Channel.DoesNotExist:
gremmie@1 25 channel = None
gremmie@1 26
gremmie@1 27 return render_to_response('podcast/index.html', {
gremmie@1 28 'channel': channel,
gremmie@1 29 },
gremmie@1 30 context_instance = RequestContext(request))
gremmie@1 31
gremmie@1 32
gremmie@1 33 def detail(request, id):
bgneal@143 34 podcast = get_object_or_404(Item.objects.select_related(), pk = id)
bgneal@143 35
bgneal@143 36 ext = get_ext_from_url(podcast.enclosure_url)
bgneal@143 37 alt_ext = None
bgneal@143 38 if podcast.alt_enclosure_url:
bgneal@143 39 alt_ext = get_ext_from_url(podcast.alt_enclosure_url)
bgneal@143 40
gremmie@1 41 return render_to_response('podcast/detail.html', {
gremmie@1 42 'channel': podcast.channel,
gremmie@1 43 'podcast': podcast,
bgneal@143 44 'ext': ext,
bgneal@143 45 'alt_ext': alt_ext,
gremmie@1 46 },
gremmie@1 47 context_instance = RequestContext(request))
gremmie@1 48
gremmie@1 49
gremmie@1 50 def feed(request):
gremmie@1 51 try:
gremmie@1 52 channel = Channel.objects.get(pk=1)
gremmie@1 53 except Channel.DoesNotExist:
gremmie@1 54 channel = None
gremmie@1 55 return render_to_response('podcast/feed.xml', {
gremmie@1 56 'channel': channel,
gremmie@1 57 },
gremmie@1 58 context_instance = RequestContext(request))