More work on new HTML reader.
[wolnelektury.git] / apps / catalogue / models / book.py
index 0438afa..b17d293 100644 (file)
@@ -95,6 +95,12 @@ class Book(models.Model):
     def name(self):
         return self.title
 
+    def language_code(self):
+        return constants.LANGUAGES_3TO2.get(self.language, self.language)
+
+    def language_name(self):
+        return dict(settings.LANGUAGES).get(self.language_code(), "")
+
     def book_tag_slug(self):
         return ('l-' + self.slug)[:120]
 
@@ -391,6 +397,10 @@ class Book(models.Model):
             for child in self.children.all():
                 child.parent_cover_changed()
 
+    def other_versions(self):
+        """Find other versions (i.e. in other languages) of the book."""
+        return type(self).objects.filter(common_slug=self.common_slug).exclude(pk=self.pk)
+
     def related_info(self):
         """Keeps info about related objects (tags, media) in cache field."""
         if self._related_info is not None:
@@ -495,7 +505,7 @@ class Book(models.Model):
         book = self
         rel_info = book.related_info()
         names = [(related_tag_name(tag), Tag.create_url('author', tag['slug']))
-                    for tag in rel_info['tags']['author']]
+                    for tag in rel_info['tags'].get('author', ())]
         if 'parents' in rel_info:
             books = [(name, Book.create_url(slug))
                         for name, slug in rel_info['parents']]