-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
47 lines (38 loc) · 1.21 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
from flask import Flask, render_template , request , redirect ,url_for
from tinydb import TinyDB, Query
import random
app = Flask(__name__)
#createing typedb
db = TinyDB('db.json')
@app.route("/")
def root():
todo_list = db.all()
return render_template('index.html',todo_list=todo_list)
@app.route("/add",methods=["POST"])
def add():
#add new item
title = request.form.get("title")
db.insert({'id':random.randint(0, 1000),'title': title, 'complete': False})
return redirect(url_for("root"))
@app.route("/update",methods=["POST"])
def update():
#update the todo titel
todo_db = Query()
newTest = request.form.get('inputField')
todo_id = request.form.get('hiddenField')
db.update({"title": newTest},todo_db.id == int(todo_id))
return redirect(url_for("root"))
@app.route("/delete/<int:todo_id>")
def delete(todo_id):
#delete the todo
todo_db = Query()
db.remove(todo_db.id == todo_id)
return redirect(url_for("root"))
@app.route("/complete/<int:todo_id>")
def complete(todo_id):
#mark complete
todo_db = Query()
db.update({"complete": True},todo_db.id == todo_id)
return redirect(url_for("root"))
if __name__ == '__main__':
app.run(debug=True)