From d66c0d42b678408921f5c3cb43c18df5b1f87338 Mon Sep 17 00:00:00 2001 From: yvesf Date: Sat, 20 Nov 2010 12:04:39 +0100 Subject: web interface --- web.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'web.py') diff --git a/web.py b/web.py index babc9dd..b262e1d 100644 --- a/web.py +++ b/web.py @@ -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/") 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/", 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=/",methods=["GET"]) @app.route("/search/",methods=["GET"]) -- cgit v1.2.1