diff --git a/__pycache__/app.cpython-310.pyc b/__pycache__/app.cpython-310.pyc index a716764..5fb102b 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 0f205bd..4f9eab1 100644 --- a/app.py +++ b/app.py @@ -77,4 +77,35 @@ def undo(id): 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 + return redirect(url_for('index')) + + +@app.route('//edit/', methods=('GET','POST')) +def edit(id): + conn = get_db_connection() + + todo = conn.execute('SELECT i.id, i.list_id, i.done, i.content, l.title \ + FROM items i JOIN lists l \ + ON i.list_id = l.id WHERE i.id = ?', (id,)).fetchone() + + lists = conn.execute('SELECT title FROM lists;').fetchall() + + if request.method == 'POST': + content = request.form['content'] + list_title = request.form['list'] + + if not content: + flash('Content is required!') + return redirect(url_for('edit', id=id)) + + list_id = conn.execute('SELECT id FROM lists WHERE title = (?);', + (list_title,)).fetchone()['id'] + + conn.execute('UPDATE items SET content = ?, list_id = ? \ + WHERE id = ?', + (content, list_id, id)) + conn.commit() + conn.close() + return redirect(url_for('index')) + + return render_template('edit.html', todo=todo, lists=lists) \ No newline at end of file diff --git a/database.db b/database.db index 70ee5c8..921ff71 100644 Binary files a/database.db and b/database.db differ diff --git a/templates/edit.html b/templates/edit.html new file mode 100644 index 0000000..c6caca4 --- /dev/null +++ b/templates/edit.html @@ -0,0 +1,41 @@ +{% extends 'base.html' %} + +{% block content %} + +

{% block title %} Edit an Item {% endblock %}

+ +
+
+ + +
+ +
+ + +
+
+ +
+
+{% endblock %} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index f6b5bc4..677980d 100644 --- a/templates/index.html +++ b/templates/index.html @@ -33,6 +33,10 @@ class="btn btn-success btn-sm"> +
+ Edit +
{% endfor %}