From 088e181cfc2b3e65c76e0ed6cb689320aaa79153 Mon Sep 17 00:00:00 2001 From: yvesf Date: Wed, 24 Nov 2010 15:27:48 +0100 Subject: web.py cleanup --- web.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'web.py') diff --git a/web.py b/web.py index a8dcbca..858019d 100644 --- a/web.py +++ b/web.py @@ -41,7 +41,7 @@ def pdf_to_image(filepath, page): if stdout: yield stdout pdffile = StringIO() - page = pyPdf.PdfFileReader(file(filepath, 'r')).getPage(page) + page = pyPdf.PdfFileReader(file(filepath, 'r')).getPage(page-1) out = pyPdf.PdfFileWriter() out.addPage(page) out.write(pdffile) @@ -69,7 +69,7 @@ def do_page_file(docnum): filepath = document['path'] page = document['pagenumber'] inputfile = pyPdf.PdfFileReader(file(filepath, 'r')) - pdfpage = inputfile.getPage(page) + pdfpage = inputfile.getPage(page-1) outbuf = StringIO() outfile = pyPdf.PdfFileWriter() outfile.addPage(pdfpage) @@ -77,13 +77,13 @@ def do_page_file(docnum): outbuf.seek(0) r = werkzeug.Response(outbuf, mimetype="application/pdf") client_filename = os.path.basename(filepath)[:-3] - client_filename += u".Page-{0}".format(page) + client_filename += u".Page-{0}.pdf".format(page) r.headers.add('Content-Disposition', 'attachment', filename=client_filename) return r class MyHtmlFormatter(highlight.HtmlFormatter): def _format_fragment(self, text, fragment, seen): -# text = unicode( flask.Markup.escape(text) ) + text = unicode( flask.Markup.escape(text) ) return highlight.HtmlFormatter._format_fragment(self, text, fragment, seen) @app.route("/excerpt//", methods=["GET"]) @@ -114,12 +114,11 @@ def excerpt(docnum, term): MyHtmlFormatter()) return unicode( excerpt ) -@app.route("/search/skip=/",methods=["GET"]) @app.route("/search/",methods=["GET"]) @app.route("/search/", methods=["GET"]) -def do_search(skip=0,term=None): - if skip == 0 and not term: - return flask.render_template('search.html', objects=[], term="", skip=0) +def do_search(term=None): + if not term: + return flask.render_template('search.html', objects=[], term="") searcher = index_book.searcher() query = QueryParser("content").parse(term) -- cgit v1.2.1