- paths = map(lambda bm: (None, bm.file.path), bm)
- return create_zip(paths, "%s_%s" % (self.slug, format_))
-
- def search_index(self, book_info=None, index=None, index_tags=True, commit=True):
- if index is None:
- from search.index import Index
- index = Index()
- try:
- index.index_book(self, book_info)
- if index_tags:
- index.index_tags()
- if commit:
- index.index.commit()
- except Exception, e:
- index.index.rollback()
- raise e
+ paths = map(lambda bm: (bm.get_nice_filename(), bm.file.path), bm)
+ licenses = set()
+ for m in bm:
+ license = constants.LICENSES.get(
+ m.get_extra_info_json().get('license'), {}
+ ).get('locative')
+ if license:
+ licenses.add(license)
+ readme = render_to_string('catalogue/audiobook_zip_readme.txt', {
+ 'licenses': licenses,
+ 'meta': self.wldocument2().meta,
+ })
+ return create_zip(paths, "%s_%s" % (self.slug, format_), {'informacje.txt': readme})
+
+ def search_index(self, index=None):
+ if not self.findable:
+ return
+ from search.index import Index
+ Index.index_book(self)
+
+ # 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):
+ 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)
+ 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)
+
+ def load_abstract(self):
+ abstract = self.wldocument(parse_dublincore=False).edoc.getroot().find('.//abstrakt')
+ if abstract is not None:
+ self.abstract = transform_abstrakt(abstract)
+ else:
+ self.abstract = ''
+
+ def load_toc(self):
+ self.toc = ''
+ if self.html_file:
+ parser = html.HTMLParser(encoding='utf-8')
+ tree = html.parse(self.html_file.path, parser=parser)
+ toc = tree.find('//div[@id="toc"]/ol')
+ if toc is None or not len(toc):
+ return
+ html_link = reverse('book_text', args=[self.slug])
+ for a in toc.findall('.//a'):
+ a.attrib['href'] = html_link + a.attrib['href']
+ self.toc = html.tostring(toc, encoding='unicode')
+ # div#toc