def text(textId): # Profiling results showing occasional lags. # Lags can be minimized by disabling SQLALCHEMY_ECHO and # and debug mode. # Tested no options, joinedload and subqueryload with no consistent winner. record = GutenbergBook.query.filter_by(textId=textId).first() # if blueprint has a different static_folder specified we might need to use blueprint.static_folder but currently None for x in record.gutenberg_files: if not mirror_exists(x): print "WARNING: Gutenberg file " + mirror_path(x.file) + " not found" record.gutenberg_files = filter(mirror_exists, record.gutenberg_files) pgid = textId2number(textId) if find_htmlz(pgid) is not None: htmlz_url = url_for('gutenberg_content_views.htmlz', pgid=pgid, path='index.html') else: htmlz_url = None if find_epub(pgid) is not None: epub_url = url_for('gutenberg_content_views.epub_ext', pgid=pgid) else: epub_url = None # fields format is list of tuples: # (Table row heading for display, gutenberg_books col name, # sub-table col name if applicable) fields = [ (_('Title'), 'title', ''), (_('Author'), 'gutenberg_creators', 'creator'), (_('Contributor'), 'gutenberg_contributors', 'contributor'), (_('Subject'), 'gutenberg_subjects', 'subject'), (_('Category'), 'gutenberg_categories', 'category'), (_('Language'), 'gutenberg_languages', 'language') ] return render_template('gutenberg/book_details.html', record=record, fields=fields, epub_url=epub_url, htmlz_url=htmlz_url)
def files_exist(textId, record=None): """Returns true if any files exist for this e-text in the local dataset""" if record is None: record = GutenbergBook.query.filter_by(textId=textId).first() if record is None: return False for x in record.gutenberg_files: if mirror_exists(x): return True pgid = textId2number(textId) if find_htmlz(pgid) is not None: return True if find_epub(pgid) is not None: return True return False
def text(textId): # Profiling results showing occasional lags. # Lags can be minimized by disabling SQLALCHEMY_ECHO and # and debug mode. # Tested no options, joinedload and subqueryload with no consistent winner. record = GutenbergBook.query.filter_by(textId=textId).first() # if blueprint has a different static_folder specified we might need to use blueprint.static_folder but currently None for x in record.gutenberg_files: if not mirror_exists(x): print "WARNING: Gutenberg file " + mirror_path( x.file) + " not found" record.gutenberg_files = filter(mirror_exists, record.gutenberg_files) pgid = textId2number(textId) if find_htmlz(pgid) is not None: htmlz_url = url_for('gutenberg_content_views.htmlz', pgid=pgid, path='index.html') else: htmlz_url = None if find_epub(pgid) is not None: epub_url = url_for('gutenberg_content_views.epub_ext', pgid=pgid) else: epub_url = None # fields format is list of tuples: # (Table row heading for display, gutenberg_books col name, # sub-table col name if applicable) fields = [(_('Title'), 'title', ''), (_('Author'), 'gutenberg_creators', 'creator'), (_('Contributor'), 'gutenberg_contributors', 'contributor'), (_('Subject'), 'gutenberg_subjects', 'subject'), (_('Category'), 'gutenberg_categories', 'category'), (_('Language'), 'gutenberg_languages', 'language')] return render_template('gutenberg/book_details.html', record=record, fields=fields, epub_url=epub_url, htmlz_url=htmlz_url)
def epub(pgid): epub_path = find_epub(pgid) if epub_path is None: print "EPub Path not found " + str(pgid) abort(404) return send_file(epub_path, mimetype='application/epub+zip')