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 filter={'image_file__isnull':False})
15 books_nav = SortedDict()
16 for tag in pictures_by_author:
17 if pictures_by_author[tag]:
18 books_nav.setdefault(tag.sort_key[0], []).append(tag)
20 return render_to_response(template_name, locals(),
21 context_instance=RequestContext(request))
24 def picture_list_thumb(request, filter=None, template_name='picture/picture_list_thumb.html'):
25 picture_list = Picture.objects.filter(image_file__isnull=False)
26 return render_to_response(template_name, locals(),
27 context_instance=RequestContext(request))
29 def picture_detail(request, slug):
30 picture = get_object_or_404(Picture, slug=slug)
32 categories = SortedDict()
33 for tag in picture.tags.iterator():
34 categories.setdefault(tag.category, []).append(tag)
38 return render_to_response("picture/picture_detail.html", locals(),
39 context_instance=RequestContext(request))
42 def picture_viewer(request, slug):
43 picture = get_object_or_404(Picture, slug=slug)
45 return render_to_response("picture/picture_viewer.html", locals(),
46 context_instance=RequestContext(request))
52 @permission_required('picture.add_picture')
53 def import_picture(request):
54 """docstring for import_book"""
55 from django.http import HttpResponse
56 from picture.forms import PictureImportForm
57 from django.utils.translation import ugettext as _
59 import_form = PictureImportForm(request.POST, request.FILES)
60 if import_form.is_valid():
68 exception = pprint.pformat(info[1])
69 tb = '\n'.join(traceback.format_tb(info[2]))
70 return HttpResponse(_("An error occurred: %(exception)s\n\n%(tb)s") % {'exception':exception, 'tb':tb}, mimetype='text/plain')
71 return HttpResponse(_("Picture imported successfully"))
73 return HttpResponse(_("Error importing file: %r") % import_form.errors)