- related_tags = models.Tag.objects.usage_for_queryset(books, counts=True,
- extra={'where': ["catalogue_tag.category NOT IN ('set', 'book', 'theme')"]})
- related_tags = (tag for tag in related_tags if tag not in tags)
- categories = split_tags(related_tags)
-
- fragments = models.Fragment.tagged.with_any(l_tags)
- categories['theme'] = models.Tag.objects.usage_for_queryset(fragments, counts=True,
- extra={'where': ["catalogue_tag.category = 'theme'"]})
-
- books = books.exclude(parent__in = book_keys)
- objects = books
+ # newtagging goes crazy if we just try:
+ #related_tags = models.Tag.objects.usage_for_queryset(books, counts=True,
+ # extra={'where': ["catalogue_tag.category NOT IN ('set', 'book', 'theme')"]})
+ if book_keys:
+ related_tags = models.Book.tags.usage(counts=True,
+ filters={'pk__in': book_keys},
+ extra={'where': ["catalogue_tag.category NOT IN ('set', 'book', 'theme')"]})
+ categories = split_tags(related_tags)
+
+ fragment_keys = [fragment.pk for fragment in models.Fragment.tagged.with_any(l_tags)]
+ if fragment_keys:
+ categories['theme'] = models.Fragment.tags.usage(counts=True,
+ filters={'pk__in': fragment_keys},
+ extra={'where': ["catalogue_tag.category = 'theme'"]})
+
+ books = books.exclude(parent__in = book_keys)
+ objects = books