From ab86dfc26dcdfc69688d4498b1b683de85a923de Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 27 Jan 2014 11:07:50 +0100 Subject: [PATCH] Other versions on book detail page. --- .../templates/catalogue/book_detail.html | 14 ++++++++++-- apps/catalogue/templatetags/catalogue_tags.py | 13 +++++------ apps/catalogue/tests/tags.py | 8 +++---- .../static/scss/main/book_box.scss | 22 ++++++++++++++----- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/apps/catalogue/templates/catalogue/book_detail.html b/apps/catalogue/templates/catalogue/book_detail.html index bb5abeb48..454bce150 100644 --- a/apps/catalogue/templates/catalogue/book_detail.html +++ b/apps/catalogue/templates/catalogue/book_detail.html @@ -15,10 +15,20 @@ {% work_list book_children %} +{% spaceless %} +{% if book.other_versions %} +
+

{% trans "Other versions" %}:

+{% for rel in book.other_versions %} + {% book_mini rel %} +{% endfor %} +
+{% endif %} -
+

{% trans "See also" %}:

-{% related_books book %} +{% related_books book taken=book.other_versions|length %}
+{% endspaceless %} {% endblock %} diff --git a/apps/catalogue/templatetags/catalogue_tags.py b/apps/catalogue/templatetags/catalogue_tags.py index e80a5ffe6..0800865ee 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -388,17 +388,14 @@ def fragment_promo(arg=None): @register.inclusion_tag('catalogue/related_books.html') -def related_books(book, limit=6, random=1): +def related_books(book, limit=6, random=1, taken=0): + limit = limit - taken cache_key = "catalogue.related_books.%d.%d" % (book.id, limit - random) related = cache.get(cache_key) if related is None: - related = list(Book.objects.filter( - common_slug=book.common_slug).exclude(pk=book.pk)[:limit]) - limit -= len(related) - if limit > random: - related += Book.tagged.related_to(book, - Book.objects.exclude(common_slug=book.common_slug), - ignore_by_tag=book.book_tag())[:limit-random] + related = Book.tagged.related_to(book, + Book.objects.exclude(common_slug=book.common_slug), + ignore_by_tag=book.book_tag())[:limit-random] cache.set(cache_key, related, 1800) if random: random_books = Book.objects.exclude( diff --git a/apps/catalogue/tests/tags.py b/apps/catalogue/tests/tags.py index 99edebbe7..c3d50e284 100644 --- a/apps/catalogue/tests/tags.py +++ b/apps/catalogue/tests/tags.py @@ -270,10 +270,10 @@ class BookTagsTests(WLTestCase): related_info = book.related_info() related_themes = book.related_themes() - self.assertEqual(related_info['tags']['author'], - [{'name_pl': 'Common Man', 'slug': 'common-man'}]) - self.assertEqual(related_info['tags']['kind'], - [{'name_pl': 'Kind', 'slug': 'kind'}]) + self.assertEqual([t['slug'] for t in related_info['tags']['author']], + ['common-man']) + self.assertEqual([t['slug'] for t in related_info['tags']['kind']], + ['kind']) self.assertEqual([(tag.name, tag.count) for tag in related_themes], [('ChildTheme', 1), ('ParentTheme', 1), ('Theme', 2)]) diff --git a/apps/wolnelektury_core/static/scss/main/book_box.scss b/apps/wolnelektury_core/static/scss/main/book_box.scss index e72bca8d0..c9b3656f1 100755 --- a/apps/wolnelektury_core/static/scss/main/book_box.scss +++ b/apps/wolnelektury_core/static/scss/main/book_box.scss @@ -6,11 +6,6 @@ @include white-box; } -.book-mini-box img.cover { - @include size(height, 193px); - @include size(width, 139px); -} - .cover-area { float: left; @@ -36,20 +31,35 @@ } .book-mini-box { - @include size(width, 161.5px); + /* Original design fits 6 boxes horizontally in 975px (162.5px each), + * but we really want to fit 2 boxes on a 320px mobile screen. */ + + @include size(width, 160px); display: inline-block; vertical-align: top; + @include min-screen(350px) { + @include size(width, 162.5px); + } + .book-mini-box-inner { @include inner-box; @include size(height, 271px); @include size(margin, 1px); + @include size(padding, 8px 9px); overflow: hidden; + + @include min-screen(350px) { + @include size(padding, 8px 10px); + } + a { display: block; } } img.cover { + @include size(height, 193px); + @include size(width, 139px); @include size(margin-bottom, 18px); } .language { -- 2.20.1