-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
57 lines (50 loc) · 1.62 KB
/
main.py
File metadata and controls
57 lines (50 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from flask import Flask, render_template, request, redirect
import mysql.connector
from datetime import date
app = Flask(__name__)
# Database connection
db = mysql.connector.connect(
host="localhost",
user="root",
password="root",
database="PYPROJECT"
)
cursor = db.cursor(dictionary=True)
@app.route('/')
def index():
cursor.execute("SELECT * FROM tasks ORDER BY deadline")
tasks = cursor.fetchall()
today = date.today()
for t in tasks:
if t['status'].lower() != 'completed':
if t['deadline'] and t['deadline'] < today:
t['remark'] = "Overdue"
elif t['deadline'] == today:
t['remark'] = "Due Today"
else:
t['remark'] = ""
else:
t['remark'] = "Done"
return render_template('index.html', tasks=tasks)
@app.route('/add', methods=['POST'])
def add_task():
title = request.form['title']
desc = request.form['description']
deadline = request.form['deadline']
priority = request.form['priority']
cursor.execute("INSERT INTO tasks (title, description, deadline, priority, status) VALUES (%s,%s,%s,%s,%s)",
(title, desc, deadline, priority, 'Pending'))
db.commit()
return redirect('/')
@app.route('/update/<int:id>')
def update_status(id):
cursor.execute("UPDATE tasks SET status='Completed' WHERE id=%s", (id,))
db.commit()
return redirect('/')
@app.route('/delete/<int:id>')
def delete_task(id):
cursor.execute("DELETE FROM tasks WHERE id=%s", (id,))
db.commit()
return redirect('/')
if __name__ == "__main__":
app.run(debug=True)