+ 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))
+
+ categories = split_tags(*related_tag_lists)
+
+ objects = list(objects)
+ 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))
+
+
+def literature(request):
+ books = Book.objects.filter(parent=None)
+
+ last_published = Book.objects.exclude(cover_thumb='').filter(parent=None).order_by('-created_at')[:20]
+ most_popular = Book.objects.exclude(cover_thumb='')\
+ .order_by('-popularity__count', 'sort_key_author', 'sort_key')[:20]
+ return object_list(request, books, related_tags=get_top_level_related_tags([]), extra={
+ 'last_published': last_published,
+ 'most_popular': most_popular,
+ })
+
+
+def gallery(request):
+ return object_list(request, Picture.objects.all(), list_type='gallery')