book children are back, + related books
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Mon, 23 Jan 2012 13:51:56 +0000 (14:51 +0100)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Mon, 23 Jan 2012 13:51:56 +0000 (14:51 +0100)
apps/catalogue/templatetags/catalogue_tags.py
wolnelektury/templates/catalogue/book_detail.html
wolnelektury/templates/catalogue/related_books.html [new file with mode: 0755]

index ba8139a..583c9c7 100644 (file)
@@ -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):
 @register.filter
 @stringfilter
 def removewholetags(value, tags):
index 5645f68..17207d1 100644 (file)
@@ -12,4 +12,8 @@
 
 {% book_wide book %}
 
 
 {% book_wide book %}
 
+{% work_list book_children %}
+
+{% related_books book %}
+
 {% endblock %}
 {% endblock %}
diff --git a/wolnelektury/templates/catalogue/related_books.html b/wolnelektury/templates/catalogue/related_books.html
new file mode 100755 (executable)
index 0000000..aad9742
--- /dev/null
@@ -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