-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
88 lines (64 loc) · 1.97 KB
/
app.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from flask import Flask, render_template, g, request
import sqlite3
app = Flask(__name__)
#DATABASE = 'database.db'
'''conn = sqlite3.connect('database.db')
print("Opened database successfully")
conn.execute('CREATE TABLE todo (task TEXT, status INTEGER DEFAULT 0)')
print("Table created successfully")
conn.close()'''
@app.route('/newtask')
def new_task():
return render_template('newtask.html')
@app.route('/addrec',methods = ['POST', 'GET'])
def addrec():
if request.method == 'POST':
task = request.form['task']
with sqlite3.connect("database.db") as con:
cur = con.cursor()
cur.execute("INSERT INTO todo (task) VALUES (?)",(task,) )
con.commit()
msg = "Record successfully added"
'''except:
con.rollback()
msg = "error in insert operation"'''
return render_template("result.html",msg = msg)
con.close()
@app.route("/done/<task>/")
def mark_as_done(task):
task_to_update = task.replace("-", " ")
with sqlite3.connect("database.db") as con:
cur = con.cursor()
cur.execute("UPDATE todo SET status = 1 WHERE task = ?",(task_to_update,) )
con.commit()
return render_template("result_archived.html", msg=task_to_update)
con.close()
@app.route('/archive')
def archive():
con = sqlite3.connect("database.db")
con.row_factory = sqlite3.Row
cur = con.cursor()
cur.execute("select * from todo")
rows = cur.fetchall();
return render_template('archive.html', rows=rows)
@app.route("/clearhistory")
def clear_history():
with sqlite3.connect("database.db") as con:
cur = con.cursor()
cur.execute("DELETE FROM todo WHERE status = 1")
con.commit()
return render_template("archive.html")
con.close()
@app.route("/about")
def about():
return render_template("about.html")
@app.route("/")
def index():
con = sqlite3.connect("database.db")
con.row_factory = sqlite3.Row
cur = con.cursor()
cur.execute("select * from todo")
rows = cur.fetchall();
return render_template("index.html",rows = rows)
if __name__ == "__main__":
app.run(debug=True)