view gpp/podcast/views.py @ 265:1ba2c6bf6eb7

Closing #98. Animated GIFs were losing their transparency and animated properties when saved as avatars. Reworked the avatar save process to only run the avatar through PIL if it is too big. This preserves the original uploaded file if it is within the desired size settings. This may still mangle big animated gifs. If this becomes a problem, then maybe look into calling the PIL Image.resize() method directly. Moved the PIL image specific functions from bio.forms to a new module: core.image for better reusability in the future.
author Brian Neal <bgneal@gmail.com>
date Fri, 24 Sep 2010 02:12:09 +0000
parents 1ed461fd2030
children 9175392da056
line wrap: on
line source
"""Views for the podcast application"""
import os.path
from urlparse import urlparse

from django.shortcuts import render_to_response
from django.template import RequestContext
from django.shortcuts import get_object_or_404

from podcast.models import Channel
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)
   except Channel.DoesNotExist:
      channel = None

   return render_to_response('podcast/index.html', {
      'channel': channel, 
      },
      context_instance = RequestContext(request))


def detail(request, 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))
   

def feed(request):
   try:
      channel = Channel.objects.get(pk=1)
   except Channel.DoesNotExist:
      channel = None
   return render_to_response('podcast/feed.xml', {
      'channel': channel, 
      },
      context_instance = RequestContext(request))