diff --git a/.gitignore b/.gitignore index 8dbe2ec..102c140 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ env/ +bak/ list.db diff --git a/main.py b/main.py index 620bd90..8960ee4 100755 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ from flask import Flask, render_template, request from pprint import pprint import sqlite3 +import time import os.path @@ -12,7 +13,8 @@ def createDB(): conn = sqlite3.connect('list.db') c = conn.cursor() c.execute('''CREATE TABLE LIST ( - requester text, item text, quatity integer, gotten text)''') + id integer PRIMARY KEY, requester text, item text, + quatity integer, gotten text, whenis real)''') conn.close() @@ -26,11 +28,23 @@ def getData(): c = conn.cursor() res = c.execute("SELECT * FROM LIST") data = res.fetchall() - pprint(data) + # pprint(data) return data -def updateDB(req): +def parseData(data): + print("Parsing Data >>") + results = [] + # pprint(data) + for x in range(len(data)): + results.append({"id": data[x][0], "req": data[x][1], + "item": data[x][2], "quantity": data[x][3], + "gotten": data[x][4], "time": data[x][5]}) + # pprint(results) + return results + + +def addRow(req): for item in req: for value in item: if value == "": @@ -39,7 +53,14 @@ def updateDB(req): with sqlite3.connect('list.db') as conn: c = conn.cursor() print(req) - c.executemany('INSERT INTO LIST VALUES (?,?,?,?)', req) + c.executemany('INSERT INTO LIST VALUES (?,?,?,?,?,?)', req) + conn.commit() + + +def haveGotten(value): + with sqlite3.connect('list.db') as conn: + c = conn.cursor() + c.executemany('UPDATE LIST SET GOTTEN = "TRUE" WHERE id = ?', value) conn.commit() createDB() @@ -50,13 +71,24 @@ app.config['DEBUG'] = True @app.route('/', methods=['POST', 'GET']) def index(): if request.method == 'POST': - req = [(request.form['requester'], request.form['item'], - request.form['quantity'], "False")] - updateDB(req) - data = getData() - return render_template('index.html', data=data) + if 'addItem' in request.form: + req = [(None, request.form['requester'], request.form['item'], + request.form['quantity'], + "False", time.mktime(time.localtime()))] + addRow(req) + tmpdata = getData() + data = parseData(tmpdata) + return render_template('index.html', data=data) + if 'gotten' in request.form: + # update DB + haveGotten(request.form['id']) + tmpdata = getData() + data = parseData(tmpdata) + return render_template('index.html', data=data) + else: - data = getData() + tmpdata = getData() + data = parseData(tmpdata) return render_template('index.html', data=data) #insTestData(2) diff --git a/templates/index.html b/templates/index.html index 068d30c..fb0c9e2 100644 --- a/templates/index.html +++ b/templates/index.html @@ -4,14 +4,14 @@
| Requester | Item | Quantity | Got It? | |
|---|---|---|---|---|
| {{ lists['req'] }} | +{{ lists['item'] }} | +{{ lists['quantity'] }} | +{% if lists['gotten'] == "False" %} + no + {% else %} + yes + {% endif %} | ++ |