+ if shelf_tags:
+ # TODO: Pictures on shelves not supported yet.
+ books = Book.tagged.with_all(shelf_tags).order_by()
+ fragments = fragments.filter(Q(book__in=books) | Q(book__ancestor__in=books))
+
+ if not fragments and len(tags) == 1 and list_type == 'books':
+ if PictureArea.tagged.with_any(tags).exists() or Picture.tagged.with_any(tags).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()),
+ }
+ }