+ return render_to_response(
+ 'catalogue/differentiate_tags.html', {'tags': tags, 'options': options, 'unparsed': ambiguous_slugs[1:]},
+ context_instance=RequestContext(request))
+
+
+def object_list(request, objects, fragments=None, related_tags=None, tags=None, list_type='books', extra=None):
+ if not tags:
+ tags = []
+ tag_ids = [tag.pk for tag in tags]
+
+ related_tag_lists = []
+ if related_tags:
+ related_tag_lists.append(related_tags)
+ else:
+ related_tag_lists.append(
+ Tag.objects.usage_for_queryset(objects, counts=True).exclude(category='set').exclude(pk__in=tag_ids))
+ if not (extra and extra.get('theme_is_set')):
+ if fragments is None:
+ if list_type == 'gallery':
+ fragments = PictureArea.objects.filter(picture__in=objects)
+ else:
+ fragments = Fragment.objects.filter(book__in=objects)
+ related_tag_lists.append(
+ Tag.objects.usage_for_queryset(fragments, counts=True).filter(category='theme').exclude(pk__in=tag_ids)
+ .only('name', 'sort_key', 'category', 'slug'))
+ if isinstance(objects, QuerySet):
+ objects = prefetch_relations(objects, 'author')
+
+ categories = split_tags(*related_tag_lists)
+
+ objects = list(objects)
+
+ if not objects 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))
+
+ if len(objects) > 3:
+ best = random.sample(objects, 3)
+ else:
+ best = objects
+
+ result = {
+ 'object_list': objects,
+ 'categories': categories,
+ 'list_type': list_type,
+ 'tags': tags,
+
+ 'formats_form': forms.DownloadFormatsForm(),
+ 'best': best,
+ 'active_menu_item': list_type,
+ }
+ if extra:
+ result.update(extra)
+ return render_to_response(
+ 'catalogue/tagged_object_list.html', result,
+ context_instance=RequestContext(request))