+
+ # newtagging goes crazy if we just try:
+ #related_tags = models.Tag.objects.usage_for_queryset(fragments, counts=True,
+ # extra={'where': ["catalogue_tag.category != 'book'"]})
+ fragment_keys = [fragment.pk for fragment in fragments]
+ if fragment_keys:
+ related_tags = models.Fragment.tags.usage(counts=True,
+ filters={'pk__in': fragment_keys},
+ extra={'where': ["catalogue_tag.category != 'book'"]})
+ related_tags = (tag for tag in related_tags if tag not in fragment_tags)
+ categories = split_tags(related_tags)
+
+ objects = fragments
+ else:
+ # get relevant books and their tags
+ objects = models.Book.tagged.with_all(tags).order_by()
+ l_tags = [book.book_tag() for book in objects]
+ # eliminate descendants
+ descendants_keys = [book.pk for book in models.Book.tagged.with_any(l_tags)]
+ if descendants_keys:
+ objects = objects.exclude(pk__in=descendants_keys)