- tags = models.Tag.objects.exclude(
- category__in=('set', 'book')).exclude(book_count=0)
- tags = list(tags)
- for tag in tags:
- tag.count = tag.book_count
- categories = split_tags(tags)
- fragment_tags = categories.get('theme', [])
-
- return render_to_response('catalogue/catalogue.html', locals(),
- context_instance=RequestContext(request))
+ #cache_key = 'catalogue.catalogue/' + get_language()
+ #output = permanent_cache.get(cache_key)
+ output = None
+
+ if output is None:
+ common_categories = ('author',)
+ split_categories = ('epoch', 'genre', 'kind')
+
+ categories = split_tags(tags_usage_for_works(common_categories))
+ book_categories = split_tags(tags_usage_for_books(split_categories))
+ picture_categories = split_tags(
+ models.Tag.objects.usage_for_model(Picture, counts=True).filter(
+ category__in=split_categories))
+ # we want global usage for themes
+ fragment_tags = list(tags_usage_for_fragments(('theme',)))
+ collections = models.Collection.objects.all()
+
+ render_tag_list = lambda x: render_to_string(
+ 'catalogue/tag_list.html', tag_list(x))
+
+ def render_split(with_books, with_pictures):
+ ctx = {}
+ if with_books:
+ ctx['books'] = render_tag_list(with_books)
+ if with_pictures:
+ ctx['pictures'] = render_tag_list(with_pictures)
+ return render_to_string('catalogue/tag_list_split.html', ctx)
+
+ output = {}
+ output['theme'] = render_tag_list(fragment_tags)
+ for category in common_categories:
+ output[category] = render_tag_list(categories.get(category, []))
+ for category in split_categories:
+ output[category] = render_split(
+ book_categories.get(category, []),
+ picture_categories.get(category, []))
+
+ output['collections'] = render_to_string(
+ 'catalogue/collection_list.html', collection_list(collections))
+ #permanent_cache.set(cache_key, output)
+ if request.is_ajax():
+ return JsonResponse(output)
+ else:
+ return render_to_response('catalogue/catalogue.html', locals(),
+ context_instance=RequestContext(request))