-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
140 lines (107 loc) · 3.34 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import os
from flask import Flask, request
from flask import render_template
from flask import redirect
from db import TaskDatabase
app = Flask(__name__)
DATA_DIR = os.path.dirname(__file__)
DB_FILE = os.path.join(DATA_DIR, 'tasks.sqlite')
db = TaskDatabase(DB_FILE)
db.create_database()
def redirect_to_form():
ref = request.headers.get('Referer')
if not ref:
ref = '/'
return redirect(ref)
@app.route('/')
def tasks_list():
hide_done = int(request.cookies.get('hide_done', 0))
if hide_done:
tasks = db.get_undone_tasks()
else:
tasks = db.get_tasks()
return render_template('list.html', tasks=tasks, hide_done=hide_done)
@app.route('/1')
def tasks_list_1():
hide_done = int(request.cookies.get('hide_done', 0))
if hide_done:
tasks = db.get_undone_tasks()
else:
tasks = db.get_tasks()
return render_template('list_1.html', tasks=tasks, hide_done=hide_done)
@app.route('/2')
def tasks_list_2():
hide_done = int(request.cookies.get('hide_done', 0))
if hide_done:
tasks = db.get_undone_tasks()
else:
tasks = db.get_tasks()
return render_template('list_2.html', tasks=tasks, hide_done=hide_done)
@app.route('/3')
def tasks_list_3():
hide_done = int(request.cookies.get('hide_done', 0))
if hide_done:
tasks = db.get_undone_tasks()
else:
tasks = db.get_tasks()
return render_template('list_3.html', tasks=tasks, hide_done=hide_done)
@app.route('/4')
def tasks_list_4():
hide_done = int(request.cookies.get('hide_done', 0))
show_recent = int(request.cookies.get('show_recent', 0))
# TODO implement the "Show recent" toggle to only show tasks that were created in the last 5 minutes
if hide_done:
tasks = db.get_undone_tasks()
else:
tasks = db.get_tasks()
return render_template('list_4.html', tasks=tasks, hide_done=hide_done, show_recent=show_recent)
@app.route('/5')
def tasks_list_5():
hide_done = int(request.cookies.get('hide_done', 0))
if hide_done:
tasks = db.get_undone_tasks()
else:
tasks = db.get_tasks()
return render_template('list_5.html', tasks=tasks, hide_done=hide_done)
@app.route('/task', methods=['POST'])
def add_task():
content = request.form['content']
if not content:
return 'Error'
db.add_task(content)
return redirect_to_form()
@app.route('/hide_done/<int:hide_done>')
def filter_tasks(hide_done):
resp = redirect_to_form()
resp.set_cookie('hide_done', str(hide_done))
return resp
@app.route('/show_recent/<int:show_recent>')
def filter_tasks_by_recency(show_recent):
resp = redirect_to_form()
resp.set_cookie('show_recent', str(show_recent))
return resp
@app.route('/delete/<int:task_id>')
def delete_task(task_id):
task = db.get_task(task_id)
if not task:
return redirect('/')
db.delete_task(task_id)
return redirect_to_form()
@app.route('/done/<int:task_id>')
def resolve_task(task_id):
db.set_task_done(task_id)
return redirect_to_form()
@app.route('/redo/<int:task_id>')
def redo_task(task_id):
# TODO
return redirect_to_form()
@app.route('/mark_all_done')
def complete_all_tasks():
# TODO
return redirect_to_form()
@app.route('/redo_all')
def redo_all_tasks():
# TODO
return redirect_to_form()
if __name__ == '__main__':
app.run()