gremmie@1: """Views for the podcast application""" bgneal@143: import os.path bgneal@143: from urlparse import urlparse gremmie@1: gremmie@1: from django.shortcuts import render_to_response gremmie@1: from django.template import RequestContext gremmie@1: from django.shortcuts import get_object_or_404 gremmie@1: gremmie@1: from podcast.models import Channel gremmie@1: from podcast.models import Item gremmie@1: gremmie@1: bgneal@143: def get_ext_from_url(url): bgneal@143: """ bgneal@143: This function returns the extension part of the path from the given bgneal@143: url. bgneal@143: """ bgneal@143: return os.path.splitext(urlparse(url).path)[1] bgneal@143: bgneal@143: gremmie@1: def index(request): gremmie@1: try: gremmie@1: channel = Channel.objects.get(pk=1) gremmie@1: except Channel.DoesNotExist: gremmie@1: channel = None gremmie@1: gremmie@1: return render_to_response('podcast/index.html', { gremmie@1: 'channel': channel, gremmie@1: }, gremmie@1: context_instance = RequestContext(request)) gremmie@1: gremmie@1: gremmie@1: def detail(request, id): bgneal@143: podcast = get_object_or_404(Item.objects.select_related(), pk = id) bgneal@143: bgneal@143: ext = get_ext_from_url(podcast.enclosure_url) bgneal@143: alt_ext = None bgneal@143: if podcast.alt_enclosure_url: bgneal@143: alt_ext = get_ext_from_url(podcast.alt_enclosure_url) bgneal@143: gremmie@1: return render_to_response('podcast/detail.html', { gremmie@1: 'channel': podcast.channel, gremmie@1: 'podcast': podcast, bgneal@143: 'ext': ext, bgneal@143: 'alt_ext': alt_ext, gremmie@1: }, gremmie@1: context_instance = RequestContext(request)) gremmie@1: gremmie@1: gremmie@1: def feed(request): gremmie@1: try: gremmie@1: channel = Channel.objects.get(pk=1) gremmie@1: except Channel.DoesNotExist: gremmie@1: channel = None gremmie@1: return render_to_response('podcast/feed.xml', { gremmie@1: 'channel': channel, gremmie@1: }, gremmie@1: context_instance = RequestContext(request))