- if (tag.category in ('theme', 'thing') and PictureArea.tagged.with_any([tag]).exists() or
- Picture.tagged.with_any([tag]).exists()):
- return redirect('tagged_object_list_gallery', raw_tags, permanent=False)
-
- return render_to_response('catalogue/tagged_object_list.html',
- {
- 'object_list': objects,
- 'categories': categories,
- 'only_shelf': only_shelf,
- 'only_my_shelf': only_my_shelf,
- 'formats_form': forms.DownloadFormatsForm(),
- 'tags': tags,
- 'tag_ids': tags_pks,
- 'theme_is_set': theme_is_set,
- 'best': best,
- 'gallery': gallery,
- },
- context_instance=RequestContext(request))
+ if tag.category == 'theme' and (
+ PictureArea.tagged.with_any([tag]).exists() or
+ Picture.tagged.with_any([tag]).exists()):
+ return redirect('tagged_object_list_gallery', '/'.join(tag.url_chunk for tag in tags))
+
+ return object_list(request, fragments, tags=tags, list_type=list_type, extra={
+ 'theme_is_set': True,
+ 'active_menu_item': 'theme',
+ })
+
+
+def tagged_object_list(request, tags, list_type):
+ try:
+ tags = analyse_tags(request, tags)
+ except ResponseInstead as e:
+ return e.response
+
+ if list_type == 'gallery' and any(tag.category == 'set' for tag in tags):
+ raise Http404
+
+ if any(tag.category in ('theme', 'thing') for tag in tags):
+ return theme_list(request, tags, list_type=list_type)
+
+ if list_type == 'books':
+ books = Book.tagged.with_all(tags)
+
+ if any(tag.category == 'set' for tag in tags):
+ params = {'objects': books}
+ else:
+ params = {
+ 'objects': Book.tagged_top_level(tags),
+ 'fragments': Fragment.objects.filter(book__in=books),
+ 'related_tags': get_top_level_related_tags(tags),
+ }
+ elif list_type == 'gallery':
+ params = {'objects': Picture.tagged.with_all(tags)}
+ elif list_type == 'audiobooks':
+ audiobooks = Book.objects.filter(media__type__in=('mp3', 'ogg')).distinct()
+ params = {
+ 'objects': Book.tagged.with_all(tags, audiobooks),
+ 'extra': {
+ 'daisy': Book.tagged.with_all(tags, audiobooks.filter(media__type='daisy').distinct()),
+ }
+ }
+ else:
+ raise Http404
+
+ return object_list(request, tags=tags, list_type=list_type, **params)