diff options
author | yvesf <yvesf-git@xapek.org> | 2010-11-24 15:27:48 +0100 |
---|---|---|
committer | yvesf <yvesf-git@xapek.org> | 2010-11-24 15:27:48 +0100 |
commit | 088e181cfc2b3e65c76e0ed6cb689320aaa79153 (patch) | |
tree | 42340cfca5a69796d35a3ef4fa44828bf19abb05 | |
parent | a12b0b0dc5d8a4a61b691a3fc20045a7b2c45270 (diff) | |
download | booksearch-088e181cfc2b3e65c76e0ed6cb689320aaa79153.tar.gz booksearch-088e181cfc2b3e65c76e0ed6cb689320aaa79153.zip |
web.py cleanup
-rw-r--r-- | web.py | 15 |
1 files changed, 7 insertions, 8 deletions
@@ -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/<int:docnum>/<path:term>", methods=["GET"]) @@ -114,12 +114,11 @@ def excerpt(docnum, term): MyHtmlFormatter()) return unicode( excerpt ) -@app.route("/search/skip=<int:skip>/<path:term>",methods=["GET"]) @app.route("/search/<path:term>",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) |