From d66c0d42b678408921f5c3cb43c18df5b1f87338 Mon Sep 17 00:00:00 2001 From: yvesf Date: Sat, 20 Nov 2010 12:04:39 +0100 Subject: web interface --- .gitignore | 1 + static/style.css | 24 ++++++++++++++++++++++++ templates/_base.html | 35 +++++++++++++++++++++++++++++++++++ templates/search.html | 44 ++++++++++++++++++++------------------------ web.py | 33 +++++++++++++++++++-------------- 5 files changed, 99 insertions(+), 38 deletions(-) create mode 100644 .gitignore create mode 100644 static/style.css create mode 100644 templates/_base.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9015a7a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +index diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..11bcece --- /dev/null +++ b/static/style.css @@ -0,0 +1,24 @@ +div#header { + font-size: 150%; +} + +div#search { + text-align: center; +} + +div#search span.preSearchField { + font-style: italic; +} + +div#content div#navigation { + text-align: center; +} + +div#footer { + position: fixed; + bottom: 0px; + padding: 4px; + background-color: white; + left: 0px; + right: 0px; +} diff --git a/templates/_base.html b/templates/_base.html new file mode 100644 index 0000000..b5826b2 --- /dev/null +++ b/templates/_base.html @@ -0,0 +1,35 @@ + + + + + {% block head %} + + {% block title %}{% endblock %} - booksearch + + {% endblock %} + + + + +
+
+ {% block content %}{% endblock %} +
+ + diff --git a/templates/search.html b/templates/search.html index 0c5f3d6..5f68355 100644 --- a/templates/search.html +++ b/templates/search.html @@ -1,18 +1,13 @@ - - - {{ objects.__len__() + skip}} matches - - - -
- - -
+{% extends "_base.html" %} +{% block title %} + {% if term != "" %} + {{ term }} + {% else %} + Start a new Search + {% endif %} +{% endblock %} +{% block searchValue %}{{ term }}{% endblock %} +{% block content %} {% if objects.__len__() == 0 %} No Matches {% else %} @@ -36,14 +31,15 @@ window.location = "/search/" + inputField.value; {% endfor %} {% endif %} -
- {% if skip > 0 %} - Previous 5 - {% else %} - Previous 5 + - - +{% endblock %} 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