comparison gpp/downloads/management/commands/dlwgetcat.py @ 528:311c926dd218

Must urlencode the filenames.
author Brian Neal <bgneal@gmail.com>
date Wed, 21 Dec 2011 01:25:10 +0000
parents 645025056dfa
children
comparison
equal deleted inserted replaced
527:645025056dfa 528:311c926dd218
32 raise CommandError("category slug '%s' does not exist" % slug) 32 raise CommandError("category slug '%s' does not exist" % slug)
33 33
34 downloads = Download.public_objects.filter(category=category).order_by( 34 downloads = Download.public_objects.filter(category=category).order_by(
35 'title').select_related() 35 'title').select_related()
36 36
37 current_site = Site.objects.get_current()
38
39 # Create new destination names for the files since the uploaders often 37 # Create new destination names for the files since the uploaders often
40 # give the files terrible names. The new names will be slugified 38 # give the files terrible names. The new names will be slugified
41 # versions of the titles, with the same extension. 39 # versions of the titles, with the same extension.
42 40
43 for dl in downloads: 41 for dl in downloads:
44 ext = os.path.splitext(dl.file.name)[1] 42 ext = os.path.splitext(dl.file.name)[1]
45 dl.dest_filename = slugify(dl.title) + ext 43 dl.dest_filename = slugify(dl.title) + ext
46 44
47 # build a full URL to the download
48 dl.full_url = 'http://%s%s%s' % (current_site.domain,
49 settings.MEDIA_URL, dl.file.name)
50
51 output = render_to_string('downloads/commands/wget_cat.html', { 45 output = render_to_string('downloads/commands/wget_cat.html', {
52 'downloads': downloads, 46 'downloads': downloads,
47 'domain': Site.objects.get_current().domain,
48 'MEDIA_URL': settings.MEDIA_URL,
53 }) 49 })
54 50
55 # encode it ourselves since it can fail if you try to redirect output to 51 # encode it ourselves since it can fail if you try to redirect output to
56 # a file and any of the content is not ASCII... 52 # a file and any of the content is not ASCII...
57 print output.encode('utf-8') 53 print output.encode('utf-8')