move updateData to /r page, only call when needed

This commit is contained in:
Adam Goldsmith 2015-08-13 11:18:51 -04:00
parent ab6b9bd247
commit af09386e83
1 changed files with 8 additions and 3 deletions

11
test.py
View File

@ -12,7 +12,9 @@ attributes= ["title",
fields = {}
@app.route("/r")
def updateData():
global data
out = []
f = zipfile.ZipFile("library.tc")
@ -63,16 +65,19 @@ def updateData():
else:
bookout[datum] = ""
out.append(bookout.copy())
return out.copy()
data = out.copy()
return "success"
@app.route("/")
def main():
data = updateData();
if data == []:
updateData()
return render_template("main.html", books = data, attributes = attributes)
@app.route("/book/<int:id>")
def book(id):
data = updateData();
if data == []:
updateData()
book = next((item for item in data if int(item["id"]) == id), {})
return render_template("book.html", book = book, fields = fields)