diff --git a/__pycache__/app.cpython-310.pyc b/__pycache__/app.cpython-310.pyc index 833a617..a716764 100644 Binary files a/__pycache__/app.cpython-310.pyc and b/__pycache__/app.cpython-310.pyc differ diff --git a/app.py b/app.py index b8f126e..0f205bd 100644 --- a/app.py +++ b/app.py @@ -22,7 +22,8 @@ app.config['SECRET KEY'] = 'this should be a secret random string' @app.route('/') def index(): conn = get_db_connection() - todos = conn.execute('SELECT i.content, l.title FROM items i JOIN lists l \ + todos = conn.execute('SELECT i.id, i.done, i.content, l.title \ + FROM items i JOIN lists l \ ON i.list_id = l.id ORDER BY l.title;').fetchall() lists = {} @@ -60,4 +61,20 @@ def create(): conn.close() return render_template('create.html', lists=lists) - \ No newline at end of file + +@app.route('//do/', methods=('POST',)) +def do(id): + conn = get_db_connection() + conn.execute('UPDATE items SET done = 1 WHERE id = ?', (id,)) + conn.commit() + conn.close() + return redirect(url_for('index')) + + +@app.route('//undo/', methods=('POST',)) +def undo(id): + conn = get_db_connection() + conn.execute('UPDATE items SET done = 0 WHERE id = ?', (id,)) + conn.commit() + conn.close() + return redirect(url_for('index')) \ No newline at end of file diff --git a/database.db b/database.db index be3b8c5..70ee5c8 100644 Binary files a/database.db and b/database.db differ diff --git a/list_example.py b/list_example.py index 67208ed..cc6bedf 100644 --- a/list_example.py +++ b/list_example.py @@ -2,7 +2,8 @@ from itertools import groupby from app import get_db_connection conn = get_db_connection() -todos = conn.execute('SELECT i.content, l.title FROM items i JOIN lists l \ +todos = conn.execute('SELECT i.id, i.done, i.content, l.title \ + FROM items i JOIN lists l \ ON i.list_id = l.id ORDER BY l.title;').fetchall() lists = {} @@ -13,4 +14,5 @@ for k, g in groupby(todos, key=lambda t: t['title']): for list_, items in lists.items(): print(list_) for item in items: - print(' ', item['content']) \ No newline at end of file + print(' ', item['content'], '| id:', + item['id'], 'done:', item['done']) \ No newline at end of file diff --git a/schema.sql b/schema.sql index 8eed966..40c290e 100644 --- a/schema.sql +++ b/schema.sql @@ -12,5 +12,6 @@ CREATE TABLE items ( list_id INTEGER NOT NULL, created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, content TEXT NOT NULL, + done INTEGER NOT NULL DEFAULT 0, FOREIGN KEY (list_id) REFERENCES lists (id) ); \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index c97680d..f6b5bc4 100644 --- a/templates/index.html +++ b/templates/index.html @@ -9,7 +9,32 @@