delete tasks

This commit is contained in:
2022-11-13 23:09:56 -05:00
parent 3a129168c1
commit 5b8d054ed8
4 changed files with 16 additions and 4 deletions

9
app.py
View File

@@ -77,4 +77,11 @@ def newTask():
@app.route('/task/<int:task_id>/')
def task(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.post('/task/<int:task_id>/delete')
def delete_task(task_id):
task = Task.query.get_or_404(task_id)
db.session.delete(task)
db.session.commit()
return redirect('/tasks')

View File

@@ -16,7 +16,7 @@
rows="5"> </textarea>
</p>
<p>
<button type="submit">Add Task</button>
<button class="btn btn-primary" type="submit">Add Task</button>
</p>
</form>
{% endblock %}

View File

@@ -18,7 +18,12 @@
<div>
<p>Due: {{ task.due_timestamp }}</p>
</div>
<hr>
<form method="POST"
action="{{url_for('delete_task',
task_id=task.id) }}">
<input class="btn btn-primary" type="submit" value="Delete Task"
onclick="return confirm('Are you sure you want to delete this task?')">
</form>
</div>
</div>
{% endblock %}

View File

@@ -14,7 +14,7 @@
{{ task.description }}
</b>
<div>
<p>Created: {{ createdTime }}</p>
<p>Created: {{ createdTime.strftime('%Y-%m-%d %I:%M %p') }}</p>
</div>
<hr>
</div>