diff options
author | yvesf <yvesf-git@xapek.org> | 2010-11-20 12:04:39 +0100 |
---|---|---|
committer | yvesf <yvesf-git@xapek.org> | 2010-11-20 12:04:39 +0100 |
commit | d66c0d42b678408921f5c3cb43c18df5b1f87338 (patch) | |
tree | 4e237edbe090f019eb76ab99bc446109469f2b2f /web.py | |
parent | edae6bad0f61ae37593aef7efd5386525562c833 (diff) | |
download | booksearch-d66c0d42b678408921f5c3cb43c18df5b1f87338.tar.gz booksearch-d66c0d42b678408921f5c3cb43c18df5b1f87338.zip |
web interface
Diffstat (limited to 'web.py')
-rw-r--r-- | web.py | 33 |
1 files changed, 19 insertions, 14 deletions
@@ -1,5 +1,6 @@ #!/usr/bin/python2.6 # coding: utf-8 +import os from StringIO import StringIO from whoosh.index import open_dir from whoosh.qparser import QueryParser @@ -21,23 +22,27 @@ def do_index(): @app.route("/download/file/<int:docnum>") def do_download_file(docnum): - document = index.reader().stored_fields(docnum) - filepath = document['path'] - return werkzeug.Response(open(filepath, "r"), mimetype="application/pdf") + document = index.reader().stored_fields(docnum) + r = werkzeug.Response(open(document['path'], "r"), mimetype="application/pdf",) + r.headers.add('Content-Disposition', 'attachment', + filename=os.path.basename(document['path'])) + return r @app.route("/download/page/<int:docnum>", methods=["GET"]) def do_download_page(docnum): - document = index.reader().stored_fields(docnum) - filepath = document['path'] - pagenumber = document['pagenumber'] - inputfile = pyPdf.PdfFileReader(file(filepath, 'r')) - page = inputfile.getPage(pagenumber) - outbuf = StringIO() - outfile = pyPdf.PdfFileWriter() - outfile.addPage(page) - outfile.write(outbuf) - outbuf.seek(0) - return werkzeug.Response(outbuf, mimetype="application/pdf") + document = index.reader().stored_fields(docnum) + inputfile = pyPdf.PdfFileReader(file(document['path'], 'r')) + page = inputfile.getPage(document['pagenumber']) + outbuf = StringIO() + outfile = pyPdf.PdfFileWriter() + outfile.addPage(page) + outfile.write(outbuf) + outbuf.seek(0) + r= werkzeug.Response(outbuf, mimetype="application/pdf") + client_filename = os.path.basename(document['path'])[:-3] + client_filename += u".Page-{0}".format(document['pagenumber']) + r.headers.add('Content-Disposition', 'attachment', filename=client_filename) + return r @app.route("/search/skip=<int:skip>/<path:term>",methods=["GET"]) @app.route("/search/<path:term>",methods=["GET"]) |