- 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'
+ output = permanent_cache.get(cache_key)
+ if output is None:
+ 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', [])
+ collections = models.Collection.objects.all()
+ render_tag_list = lambda x: render_to_string(
+ 'catalogue/tag_list.html', tag_list(x))
+ output = {'theme': render_tag_list(fragment_tags)}
+ for category, tags in categories.items():
+ output[category] = render_tag_list(tags)
+ 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))