1 from picture.models import Picture
2 from django.contrib.auth.decorators import permission_required
3 from django.utils.datastructures import SortedDict
4 from django.shortcuts import render_to_response, get_object_or_404
5 from django.template import RequestContext
8 def picture_list(request, filter=None, template_name='catalogue/picture_list.html'):
9 """ generates a listing of all books, optionally filtered with a test function """
11 pictures_by_author, orphans = Picture.picture_list()
12 books_nav = SortedDict()
13 for tag in pictures_by_author:
14 if pictures_by_author[tag]:
15 books_nav.setdefault(tag.sort_key[0], []).append(tag)
17 # import pdb; pdb.set_trace()
18 return render_to_response(template_name, locals(),
19 context_instance=RequestContext(request))
22 def picture_detail(request, picture):
23 picture = get_object_or_404(Picture, slug=picture)
25 categories = SortedDict()
26 for tag in picture.tags:
27 categories.setdefault(tag.category, []).append(tag)
31 return render_to_response("catalogue/picture_detail.html", locals(),
32 context_instance=RequestContext(request))
37 @permission_required('picture.add_picture')
38 def import_picture(request):
39 """docstring for import_book"""
40 from django.http import HttpResponse
41 from picture.forms import PictureImportForm
42 from django.utils.translation import ugettext as _
44 import_form = PictureImportForm(request.POST, request.FILES)
45 if import_form.is_valid():
53 exception = pprint.pformat(info[1])
54 tb = '\n'.join(traceback.format_tb(info[2]))
55 return HttpResponse(_("An error occurred: %(exception)s\n\n%(tb)s") % {'exception':exception, 'tb':tb}, mimetype='text/plain')
56 return HttpResponse(_("Picture imported successfully"))
58 return HttpResponse(_("Error importing file: %r") % import_form.errors)