- model = models.Fragment
- only_author = len(tags) == 1 and tags[0].category == 'author'
- pd_counter = only_author and tags[0].goes_to_pd()
-
- user_is_owner = (len(shelf) and request.user.is_authenticated() and request.user == shelf[0].user)
+ shelf_tags = [tag for tag in tags if tag.category == 'set']
+ fragment_tags = [tag for tag in tags if tag.category != 'set']
+ fragments = models.Fragment.tagged.with_all(fragment_tags)
+
+ if shelf_tags:
+ books = models.Book.tagged.with_all(shelf_tags)
+ l_tags = [models.Tag.objects.get(slug = 'l-' + book.slug) for book in books]
+ fragments = (fragment for fragment in models.Fragment.tagged.with_any(l_tags) if fragment in fragments)
+
+ 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:
+ books = models.Book.tagged.with_all(tags)
+ l_tags = [models.Tag.objects.get(slug = 'l-' + book.slug) for book in books]
+ book_keys = [book.pk for book in books]
+ 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)