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
8 from catalogue.utils import split_tags
10 # was picture/picture_list.html list (without thumbs)
11 def picture_list(request, filter=None, get_filter=None, template_name='catalogue/picture_list.html', cache_key=None, context=None):
12 """ generates a listing of all books, optionally filtered with a test function """
16 pictures_by_author, orphans = Picture.picture_list(filt)
17 books_nav = SortedDict()
18 for tag in pictures_by_author:
19 if pictures_by_author[tag]:
20 books_nav.setdefault(tag.sort_key[0], []).append(tag)
22 return render_to_response(template_name, locals(),
23 context_instance=RequestContext(request))
26 def picture_list_thumb(request, filter=None, get_filter=None, template_name='picture/picture_list_thumb.html', cache_key=None, context=None):
27 book_list = Picture.objects.all()
29 book_list = book_list.filter(filter)
31 book_list = book_list.filter(get_filter())
32 book_list = list(book_list)
33 book_list.sort(lambda a,b: cmp(a.extra_info['authors'][0], b.extra_info['authors'][0]))
34 return render_to_response(template_name, locals(),
35 context_instance=RequestContext(request))
37 def picture_detail(request, slug):
38 picture = get_object_or_404(Picture, slug=slug)
40 theme_things = split_tags(picture.related_themes())
42 # categories = SortedDict()
43 # for tag in picture.tags.iterator():
44 # categories.setdefault(tag.category, []).append(tag)
46 themes = theme_things.get('theme', [])
47 things = theme_things.get('thing', [])
49 extra_info = picture.extra_info
51 return render_to_response("picture/picture_detail.html", locals(),
52 context_instance=RequestContext(request))
55 def picture_viewer(request, slug):
56 picture = get_object_or_404(Picture, slug=slug)
57 return render_to_response("picture/picture_viewer.html", locals(),
58 context_instance=RequestContext(request))
64 @permission_required('picture.add_picture')
65 def import_picture(request):
66 """docstring for import_book"""
67 from django.http import HttpResponse
68 from picture.forms import PictureImportForm
69 from django.utils.translation import ugettext as _
71 import_form = PictureImportForm(request.POST, request.FILES)
72 if import_form.is_valid():
80 exception = pprint.pformat(info[1])
81 tb = '\n'.join(traceback.format_tb(info[2]))
82 return HttpResponse(_("An error occurred: %(exception)s\n\n%(tb)s") % {'exception':exception, 'tb':tb}, mimetype='text/plain')
83 return HttpResponse(_("Picture imported successfully"))
85 return HttpResponse(_("Error importing file: %r") % import_form.errors)