begin edit task function

This commit is contained in:
2022-11-14 18:49:00 -05:00
parent 314511833b
commit 38b3cf9525
2 changed files with 30 additions and 0 deletions

8
app.py
View File

@@ -79,6 +79,14 @@ def task(task_id):
task = Task.query.get_or_404(task_id) task = Task.query.get_or_404(task_id)
return render_template('task.html', str=str, task=task, datetime=datetime, date=date) return render_template('task.html', str=str, task=task, datetime=datetime, date=date)
@app.route('/task/<int:task_id>/edit', methods=('GET', 'POST'))
def editTask(task_id):
task = Task.query.get_or_404(task_id)
if request.method == 'POST':
task.title = request.form['title']
task.description = request.form['description']
db.session.commit()
return render_template('edittask.html', str=str, task=task, datetime=datetime, date=date)
@app.post('/task/<int:task_id>/delete') @app.post('/task/<int:task_id>/delete')
def delete_task(task_id): def delete_task(task_id):
task = Task.query.get_or_404(task_id) task = Task.query.get_or_404(task_id)

22
templates/edittask.html Normal file
View File

@@ -0,0 +1,22 @@
{% extends 'base.html' %}
{% block content %}
<span><h1>{% block title %} Edit Task {% endblock %}</h1></span>
<form method="post">
<p>
<label for="title">Title:</label><br>
<input type="text" id="title" name="title"><br>
</p>
<p>
<label for="description">Description</label><br>
<textarea id="description"
name="description"
cols="25"
rows="5"> </textarea>
</p>
<p>
<button class="btn btn-primary" type="submit">Edit Task</button>
</p>
</form>
{% endblock %}