translator in book box
authorJan Szejko <janek37@gmail.com>
Wed, 7 Jun 2017 12:43:05 +0000 (14:43 +0200)
committerJan Szejko <janek37@gmail.com>
Wed, 7 Jun 2017 12:43:05 +0000 (14:43 +0200)
src/catalogue/models/book.py
src/catalogue/templates/catalogue/book_short.html

index db50f3e..6527d11 100644 (file)
@@ -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
 
index 0d64409..35f4a4c 100644 (file)
           <div class="title">
             {% if main_link %}<a href="{{ main_link }}">{% endif %}{{ book.title }}{% if main_link %}</a>{% endif %}
           </div>
+          {% if book.translator %}
+              <div class="author">
+                  tłum. {{ book.translator }}
+              </div>
+          {% endif %}
         </div>
 
         <div class="cover-area">