From: Radek Czajka Date: Mon, 23 Jan 2012 13:51:56 +0000 (+0100) Subject: book children are back, + related books X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/b2d05b5ed588e0829c4cec01796a20a803b301db?ds=sidebyside;hp=-c book children are back, + related books --- b2d05b5ed588e0829c4cec01796a20a803b301db diff --git a/apps/catalogue/templatetags/catalogue_tags.py b/apps/catalogue/templatetags/catalogue_tags.py index ba8139a5e..583c9c763 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -339,6 +339,27 @@ def fragment_promo(arg=None): } +@register.inclusion_tag('catalogue/related_books.html') +def related_books(book, limit=6): + related = list(Book.objects.filter( + common_slug=book.common_slug).exclude(pk=book.pk)[:limit]) + limit -= len(related) + if limit: + tagged = Book.tagged.with_any(book.tags).exclude(pk=book.pk) + book_tag = book.book_tag() + for rel_book in tagged: + if book_tag in rel_book.tags.all(): + continue + related += [rel_book] + limit -= 1 + if not limit: + break + + return { + 'books': related, + } + + @register.filter @stringfilter def removewholetags(value, tags): diff --git a/wolnelektury/templates/catalogue/book_detail.html b/wolnelektury/templates/catalogue/book_detail.html index 5645f68ec..17207d1b7 100644 --- a/wolnelektury/templates/catalogue/book_detail.html +++ b/wolnelektury/templates/catalogue/book_detail.html @@ -12,4 +12,8 @@ {% book_wide book %} +{% work_list book_children %} + +{% related_books book %} + {% endblock %} diff --git a/wolnelektury/templates/catalogue/related_books.html b/wolnelektury/templates/catalogue/related_books.html new file mode 100755 index 000000000..aad9742f5 --- /dev/null +++ b/wolnelektury/templates/catalogue/related_books.html @@ -0,0 +1,7 @@ +{% load book_mini from catalogue_tags %} + +{% spaceless %} +{% for book in books %} + {% book_mini book %} +{% endfor %} +{% endspaceless %} \ No newline at end of file