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 | |
parent | edae6bad0f61ae37593aef7efd5386525562c833 (diff) | |
download | booksearch-d66c0d42b678408921f5c3cb43c18df5b1f87338.tar.gz booksearch-d66c0d42b678408921f5c3cb43c18df5b1f87338.zip |
web interface
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | static/style.css | 24 | ||||
-rw-r--r-- | templates/_base.html | 35 | ||||
-rw-r--r-- | templates/search.html | 44 | ||||
-rw-r--r-- | web.py | 33 |
5 files changed, 99 insertions, 38 deletions
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 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> +<html lang="en"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> + {% block head %} + <link rel="stylesheet" href="{{ url_for("static", filename="style.css") }}" /> + <title>{% block title %}{% endblock %} - booksearch</title> + <script> + function start() { + var inputField = document.getElementById("searchInput"); + window.location = "/search/" + inputField.value; + return false; + } + </script> + {% endblock %} +</head> +<body> + <div id="header"> + booksearch + </div> + <div id="search"> + <span class="preSearchField">Search:</span> + <input id="searchInput" type="text" value="{% block searchValue %}{% endblock %}" placeholder="terms..." /> + <button onclick="start()">Senden</button> + </div> + <hr /> + <div id="content"> + {% block content %}{% endblock %} + </div> + <div id="footer"> + {% block footer %} + 2010 - booksearch + {% endblock %} + </div> +</body> 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 @@ -<html> - <head> - <title>{{ objects.__len__() + skip}} matches</title> -<script> -function start() { -var inputField = document.getElementById("search"); -window.location = "/search/" + inputField.value; -} -</script> - </head> - <body> -<div> -<input id="search" type="text"/> -<button onclick="start()">Go</button> -</div> +{% 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 %} - <div> - {% if skip > 0 %} - <a href="{{ url_for("do_search", term=term, skip=skip-5) }}">Previous 5</a> - {% else %} - Previous 5 + <div id="navigation"> + {% if term != "" %} + {% if skip > 0 %} + <a href="{{ url_for("do_search", term=term, skip=skip-5) }}">Previous 5</a> + {% else %} + Previous 5 + {% endif %} + - + <a href="{{ url_for("do_search", term=term, skip=skip+5) }}">Next 5</a> {% endif %} - - - <a href="{{ url_for("do_search", term=term, skip=skip+5) }}">Next 5</a> </div> - </body> -</html> +{% endblock %} @@ -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"]) |