adjust img width
[wolnelektury.git] / src / catalogue / models / book.py
index f1501d0..d3e2a77 100644 (file)
@@ -153,6 +153,9 @@ class Book(models.Model):
     def language_name(self):
         return dict(settings.LANGUAGES).get(self.language_code(), "")
 
+    def is_foreign(self):
+        return self.language_code() != settings.LANGUAGE_CODE
+
     def has_media(self, type_):
         if type_ in Book.formats:
             return bool(getattr(self, "%s_file" % type_))
@@ -251,9 +254,10 @@ class Book(models.Model):
     def download_pictures(self, remote_gallery_url):
         gallery_path = self.gallery_path()
         # delete previous files, so we don't include old files in ebooks
-        for filename in os.listdir(gallery_path):
-            file_path = os.path.join(gallery_path, filename)
-            os.unlink(file_path)
+        if os.path.isdir(gallery_path):
+            for filename in os.listdir(gallery_path):
+                file_path = os.path.join(gallery_path, filename)
+                os.unlink(file_path)
         ilustr_elements = list(self.wldocument().edoc.findall('//ilustr'))
         if ilustr_elements:
             makedirs(gallery_path)