now with the ability to post new tasks
This commit is contained in:
14
app.py
14
app.py
@@ -1,5 +1,6 @@
|
|||||||
import os
|
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 import Flask, render_template, request, redirect, url_for
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
|
||||||
@@ -62,6 +63,17 @@ def tasks():
|
|||||||
tasks = Task.query.all()
|
tasks = Task.query.all()
|
||||||
return render_template('tasks.html', str=str, tasks=tasks, datetime=datetime, date=date)
|
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/<int:task_id>/')
|
@app.route('/task/<int:task_id>/')
|
||||||
def task(task_id):
|
def task(task_id):
|
||||||
task = Task.query.get_or_404(task_id)
|
task = Task.query.get_or_404(task_id)
|
||||||
|
22
templates/newtask.html
Normal file
22
templates/newtask.html
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<span><h1>{% block title %} Create New 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 type="submit">Add Task</button>
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
@@ -1,7 +1,7 @@
|
|||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<span><h1>{% block title %} Tasks {% endblock %}</h1></span> <br>
|
<span><h1>{% block title %} Tasks {% endblock %}</h1></span> <a class="btn btn-primary" href="/task/new" role="button">New Task</a> <br> <br>
|
||||||
<div>
|
<div>
|
||||||
{% for task in tasks %}
|
{% for task in tasks %}
|
||||||
{% set createdTime = datetime.fromtimestamp(task.created_timestamp) %}
|
{% set createdTime = datetime.fromtimestamp(task.created_timestamp) %}
|
||||||
|
Reference in New Issue
Block a user