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
6 from django.core.paginator import Paginator
7 from picture.models import Picture
10 def picture_list(request, filter=None, template_name='catalogue/picture_list.html'):
11 """ generates a listing of all books, optionally filtered with a test function """
13 pictures_by_author, orphans = Picture.picture_list()
14 books_nav = SortedDict()
15 for tag in pictures_by_author:
16 if pictures_by_author[tag]:
17 books_nav.setdefault(tag.sort_key[0], []).append(tag)
19 return render_to_response(template_name, locals(),
20 context_instance=RequestContext(request))
23 def picture_list_thumb(request, filter=None, template_name='picture/picture_list_thumb.html'):
24 picture_list = Picture.objects.all()
25 return render_to_response(template_name, locals(),
26 context_instance=RequestContext(request))
28 def picture_detail(request, slug):
29 picture = get_object_or_404(Picture, slug=slug)
31 categories = SortedDict()
32 for tag in picture.tags.iterator():
33 categories.setdefault(tag.category, []).append(tag)
37 return render_to_response("picture/picture_detail.html", locals(),
38 context_instance=RequestContext(request))
41 def picture_viewer(request, slug):
42 picture = get_object_or_404(Picture, slug=slug)
44 return render_to_response("picture/picture_viewer.html", locals(),
45 context_instance=RequestContext(request))
51 @permission_required('picture.add_picture')
52 def import_picture(request):
53 """docstring for import_book"""
54 from django.http import HttpResponse
55 from picture.forms import PictureImportForm
56 from django.utils.translation import ugettext as _
58 import_form = PictureImportForm(request.POST, request.FILES)
59 if import_form.is_valid():
67 exception = pprint.pformat(info[1])
68 tb = '\n'.join(traceback.format_tb(info[2]))
69 return HttpResponse(_("An error occurred: %(exception)s\n\n%(tb)s") % {'exception':exception, 'tb':tb}, mimetype='text/plain')
70 return HttpResponse(_("Picture imported successfully"))
72 return HttpResponse(_("Error importing file: %r") % import_form.errors)