add pages for books

This commit is contained in:
Adam Goldsmith 2015-08-08 19:31:48 -04:00
parent aaad29dc45
commit d560380166
2 changed files with 14 additions and 0 deletions

8
templates/book.html Normal file
View File

@ -0,0 +1,8 @@
<!doctype html>
<title>{{book["title"]}}</title>
{% if book["image"] is not equalto "" %}
<p> cover: <img src="{{ url_for('static', filename="library_files/" + book["image"]) }}"> </p>
{% endif %}
{% for datum in (book|dictsort) %}
<p> {{datum[0]}}: {{ datum[1] }} </p>
{% endfor %}

View File

@ -20,6 +20,7 @@ def updateData():
for book in collection.iter(ns + "entry"):
bookout = {}
bookout["id"] = int(book.find(ns + "id").text)
bookout["title"] = book.find(ns + "title").text if (book.find(ns + "title") != None) else ""
bookout["isbn"] = book.find(ns + "isbn").text if (book.find(ns + "isbn") != None) else ""
authors = []
@ -36,6 +37,11 @@ def main():
data = updateData();
return render_template("main.html", books = data, attributes = attributes)
@app.route("/book/<int:id>")
def book(id):
data = updateData();
book = next((item for item in data if item["id"] == id), {})
return render_template("book.html", book = book)
if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0')