- if list_type in ('books', 'audiobooks'):
- return TaggedObjectList.as_view()(request, tags=tags)
-
- 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:
- books = books.filter(findable=True)
- params = {
- 'objects': Book.tagged_top_level(tags).filter(findable=True),
- '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(findable=True, 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)