From 89b615b771a8158cdb9f3f9fecd8301686f0da02 Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Wed, 7 Jun 2017 14:43:05 +0200 Subject: [PATCH 1/1] translator in book box --- src/catalogue/models/book.py | 11 +++++++++++ src/catalogue/templates/catalogue/book_short.html | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/src/catalogue/models/book.py b/src/catalogue/models/book.py index db50f3e3c..6527d11d6 100644 --- a/src/catalogue/models/book.py +++ b/src/catalogue/models/book.py @@ -121,6 +121,17 @@ class Book(models.Model): def author_unicode(self): return self.tag_unicode('author') + def translator(self): + translators = self.extra_info.get('translators') + if not translators: + return None + if len(translators) > 3: + translators = translators[:2] + others = ' i inni' + else: + others = '' + return ', '.join(u'\xa0'.join(reversed(translator.split(', ', 1))) for translator in translators) + others + def save(self, force_insert=False, force_update=False, **kwargs): from sortify import sortify diff --git a/src/catalogue/templates/catalogue/book_short.html b/src/catalogue/templates/catalogue/book_short.html index 0d644093b..35f4a4c61 100644 --- a/src/catalogue/templates/catalogue/book_short.html +++ b/src/catalogue/templates/catalogue/book_short.html @@ -25,6 +25,11 @@
{% if main_link %}{% endif %}{{ book.title }}{% if main_link %}{% endif %}
+ {% if book.translator %} +
+ tłum. {{ book.translator }} +
+ {% endif %}
-- 2.20.1