comparison bns_website/videos/admin.py @ 62:93e9e7b3d2ae

Put in an import dance for Python 2.5. Apparently cgi.parse_qs was copied to urlparse in Python 2.6. So look for it first in urlparse, and if not found, try cgi.
author Brian Neal <bgneal@gmail.com>
date Sat, 19 Nov 2011 14:47:17 -0600
parents a0d3bc630ebd
children
comparison
equal deleted inserted replaced
61:1d2473f4bcaa 62:93e9e7b3d2ae
2 Automatic admin definitions for the videos application. 2 Automatic admin definitions for the videos application.
3 3
4 """ 4 """
5 import datetime 5 import datetime
6 import urlparse 6 import urlparse
7
8 try:
9 from urlparse import parse_qs
10 except ImportError:
11 from cgi import parse_qs # for Python 2.5
7 12
8 from django.contrib import admin 13 from django.contrib import admin
9 from django.contrib import messages 14 from django.contrib import messages
10 from gdata.youtube.service import YouTubeService 15 from gdata.youtube.service import YouTubeService
11 16
29 YouTube playlist. 34 YouTube playlist.
30 35
31 """ 36 """
32 # Find the playlist ID: 37 # Find the playlist ID:
33 parts = urlparse.urlparse(playlist.playlist_url) 38 parts = urlparse.urlparse(playlist.playlist_url)
34 query = urlparse.parse_qs(parts.query) 39 query = parse_qs(parts.query)
35 if 'list' not in query: 40 if 'list' not in query:
36 messages.error(request, 'Invalid playlist %s' % 41 messages.error(request, 'Invalid playlist %s' %
37 playlist.playlist_url) 42 playlist.playlist_url)
38 return 43 return
39 44
67 72
68 vid_ids = [] 73 vid_ids = []
69 for vid in vids: 74 for vid in vids:
70 for link in vid.link: 75 for link in vid.link:
71 parts = urlparse.urlparse(link.href) 76 parts = urlparse.urlparse(link.href)
72 query = urlparse.parse_qs(parts.query) 77 query = parse_qs(parts.query)
73 if 'v' in query: 78 if 'v' in query:
74 vid_ids.append(query['v'][0]) 79 vid_ids.append(query['v'][0])
75 break 80 break
76 else: 81 else:
77 messages.error(request, "%s: video id not found for %s" % 82 messages.error(request, "%s: video id not found for %s" %