X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/0f14f604bfe3981f2b66726fb69ec0b710150bcc..06175c1d644d5a6f3093c945f18d6b3c33cc8d46:/src/catalogue/models/book.py?ds=inline diff --git a/src/catalogue/models/book.py b/src/catalogue/models/book.py index 2371103e7..6b9fd72b3 100644 --- a/src/catalogue/models/book.py +++ b/src/catalogue/models/book.py @@ -296,23 +296,24 @@ class Book(models.Model): return self.parent.get_prev_text() - def get_next_text(self): - child = self.children.order_by('parent_number').first() - if child is not None: - return child.get_first_text() + def get_next_text(self, inside=True): + if inside: + child = self.children.order_by('parent_number').first() + if child is not None: + return child.get_first_text() if not self.parent: return None sibling = self.parent.children.filter(parent_number__gt=self.parent_number).order_by('parent_number').first() if sibling is not None: return sibling.get_first_text() - return self.parent.get_next_text() + return self.parent.get_next_text(inside=False) def get_child_audiobook(self): BookMedia = apps.get_model('catalogue', 'BookMedia') if not BookMedia.objects.filter(book__ancestor=self).exists(): return None - for child in self.children.all(): + for child in self.children.order_by('parent_number').all(): if child.has_mp3_file(): return child child_sub = child.get_child_audiobook() @@ -560,6 +561,7 @@ class Book(models.Model): # will make problems in conjunction with paid previews def download_pictures(self, remote_gallery_url): + # This is only needed for legacy relative image paths. gallery_path = self.gallery_path() # delete previous files, so we don't include old files in ebooks if os.path.isdir(gallery_path): @@ -571,6 +573,8 @@ class Book(models.Model): makedirs(gallery_path) for ilustr in ilustr_elements: ilustr_src = ilustr.get('src') + if '/' in ilustr_src: + continue ilustr_path = os.path.join(gallery_path, ilustr_src) urlretrieve('%s/%s' % (remote_gallery_url, ilustr_src), ilustr_path)