Beispiel #1
0
    def save(self, *args, **kwargs):
        if not self.cover_img:
            if self.book_file.name.endswith('.epub'):
                # get the cover path from the epub file
                epub_file = Epub(self.book_file)
                cover_path = epub_file.get_cover_image_path()
                if cover_path is not None and os.path.exists(cover_path):
                    cover_file = File(open(cover_path))
                    self.cover_img.save(os.path.basename(cover_path),
                                        cover_file)
                epub_file.close()

        super(Book, self).save(*args, **kwargs)