def footer_html(self): candidates = filename_candidates( self.document, prefix='indigo_api/akn/export/pdf_footer_', suffix='.html') best = find_best_template(candidates) if not best: raise ValueError("Couldn't find footer file for PDF.") return get_template(best).origin.name
def toc_xsl(self): candidates = filename_candidates( self.document, prefix='indigo_api/akn/export/pdf_toc_', suffix='.xsl') best = find_best_template(candidates) if not best: raise ValueError("Couldn't find TOC XSL file for PDF.") return get_template(best).origin.name
def find_template(self, document, prefix='', suffix='.html'): """ Return the filename of a template to use to render this document. The normal Django templating system is used to find a template. The first template found is used. """ candidates = filename_candidates(document, prefix='indigo_api/akn/' + prefix, suffix=suffix) best = find_best_template(candidates) if not best: raise ValueError("Couldn't find an HTML template to use for %s, tried: %s" % (document, candidates)) return best
def render_colophon(self, colophon, document, documents): # find the wrapper template candidates = filename_candidates(document, prefix='indigo_api/akn/export/epub_colophon_', suffix='.html') best = find_best_template(candidates) if not best: raise ValueError("Couldn't find colophon file for EPUB.") colophon_wrapper = get_template(best).origin.name return render_to_string(colophon_wrapper, { 'colophon': colophon, 'document': document, 'documents': documents, })
def render_colophon(self, document=None, documents=None): """ Find the colophon template this document and render it, returning the rendered HTML. This renders the colophon using a wrapper template to ensure it's a full HTML document. """ colophon = self.find_colophon(document or documents[0]) if colophon: # find the wrapper template candidates = filename_candidates(self.document, prefix='indigo_api/akn/export/pdf_colophon_', suffix='.html') best = find_best_template(candidates) if not best: raise ValueError("Couldn't find colophon file for PDF.") colophon_wrapper = get_template(best).origin.name html = render_to_string(colophon_wrapper, { 'colophon': colophon, 'document': document, 'documents': documents, }) return make_absolute_paths(html)