-from catalogue.utils import split_tags
-from newtagging import views as newtagging_views
-
-
-class LazyEncoder(simplejson.JSONEncoder):
- def default(self, obj):
- if isinstance(obj, Promise):
- return force_unicode(obj)
- return obj
-
-
-@cache.cache_control(must_revalidate=True, max_age=3600)
-def main_page(request):
- if request.user.is_authenticated():
- shelves = models.Tag.objects.filter(category='set', user=request.user)
- new_set_form = forms.NewSetForm()
- extra_where = 'NOT catalogue_tag.category = "set"'
- tags = models.Tag.objects.usage_for_model(models.Book, counts=True, extra={'where': [extra_where]})
- fragment_tags = models.Tag.objects.usage_for_model(models.Fragment, counts=True,
- extra={'where': ['catalogue_tag.category = "theme"'] + [extra_where]})
- categories = split_tags(tags)
-
- form = forms.SearchForm()
- return render_to_response('catalogue/main_page.html', locals(),
- context_instance=RequestContext(request))
+from .helpers import get_related_tags, get_fragment_related_tags, tags_usage_for_books, tags_usage_for_works, tags_usage_for_fragments
+from catalogue.utils import split_tags, MultiQuerySet, SortedMultiQuerySet
+from catalogue.templatetags.catalogue_tags import tag_list, collection_list
+from pdcounter import models as pdcounter_models
+from pdcounter import views as pdcounter_views
+from suggest.forms import PublishingSuggestForm
+from picture.models import Picture, PictureArea
+from picture.views import picture_list_thumb
+
+staff_required = user_passes_test(lambda user: user.is_staff)
+permanent_cache = get_cache('permanent')
+
+
+@vary_on_headers('X-Requested-With')
+def catalogue(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))