From 3a129168c1b16c00095b739d14371dae97c4243e Mon Sep 17 00:00:00 2001 From: William Peebles Date: Sun, 13 Nov 2022 14:21:23 -0500 Subject: [PATCH] now with the ability to post new tasks --- app.py | 14 +++++++++++++- templates/newtask.html | 22 ++++++++++++++++++++++ templates/tasks.html | 2 +- 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 templates/newtask.html diff --git a/app.py b/app.py index b4f52be..1e775fe 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,6 @@ import os -from datetime import datetime, time, date +import time +from datetime import datetime, date from flask import Flask, render_template, request, redirect, url_for from flask_sqlalchemy import SQLAlchemy @@ -62,6 +63,17 @@ def tasks(): tasks = Task.query.all() return render_template('tasks.html', str=str, tasks=tasks, datetime=datetime, date=date) +@app.route('/task/new', methods=('GET', 'POST')) +def newTask(): + if request.method == 'POST': + task = Task(title=request.form['title'], + description=request.form['description'], + created_timestamp=int(time.time())) + db.session.add(task) + db.session.commit() + return redirect(f'/task/{task.id}') + return render_template('newtask.html') + @app.route('/task//') def task(task_id): task = Task.query.get_or_404(task_id) diff --git a/templates/newtask.html b/templates/newtask.html new file mode 100644 index 0000000..5a36fa0 --- /dev/null +++ b/templates/newtask.html @@ -0,0 +1,22 @@ +{% extends 'base.html' %} + +{% block content %} +

{% block title %} Create New Task {% endblock %}

+
+

+
+
+

+ +

+
+ +

+

+ +

+
+{% endblock %} \ No newline at end of file diff --git a/templates/tasks.html b/templates/tasks.html index 399cf79..b95045b 100644 --- a/templates/tasks.html +++ b/templates/tasks.html @@ -1,7 +1,7 @@ {% extends 'base.html' %} {% block content %} -

{% block title %} Tasks {% endblock %}


+

{% block title %} Tasks {% endblock %}

New Task

{% for task in tasks %} {% set createdTime = datetime.fromtimestamp(task.created_timestamp) %}