|
|
|
|
@ -14,21 +14,28 @@ app = Flask(__name__)
|
|
|
|
|
|
|
|
|
|
@app.get("/")
|
|
|
|
|
def show_all():
|
|
|
|
|
cursor.execute('SELECT * FROM items')
|
|
|
|
|
cursor.execute('SELECT * FROM items WHERE parent_id IS NULL')
|
|
|
|
|
return render_template('show.html', cursor=cursor)
|
|
|
|
|
|
|
|
|
|
@app.post("/")
|
|
|
|
|
def create():
|
|
|
|
|
cursor.execute('INSERT INTO items (title, description) VALUES(%s,%s)', [request.form['title'],request.form['description']])
|
|
|
|
|
return redirect('/')
|
|
|
|
|
if 'parent_id' in request.form:
|
|
|
|
|
cursor.execute('INSERT INTO items (title, description,parent_id) VALUES(%s,%s,%s)', [request.form['title'],request.form['description'],int(request.form['parent_id'])])
|
|
|
|
|
return redirect('/'+request.form['parent_id'])
|
|
|
|
|
else:
|
|
|
|
|
cursor.execute('INSERT INTO items (title, description) VALUES(%s,%s)', [request.form['title'],request.form['description']])
|
|
|
|
|
return redirect('/')
|
|
|
|
|
|
|
|
|
|
@app.post("/<id>")
|
|
|
|
|
def delete(id):
|
|
|
|
|
# print(request.args.get('_method'))
|
|
|
|
|
# TODO: deal with deleting item that has children
|
|
|
|
|
cursor.execute('DELETE FROM items WHERE id=%s LIMIT 1', [id])
|
|
|
|
|
return redirect('/')
|
|
|
|
|
|
|
|
|
|
@app.get("/<id>")
|
|
|
|
|
def show(id):
|
|
|
|
|
cursor.execute('SELECT * FROM items WHERE id=%s', [id])
|
|
|
|
|
return render_template('show.html', cursor=cursor)
|
|
|
|
|
parent=cursor.fetchone()
|
|
|
|
|
cursor.execute('SELECT * FROM items WHERE parent_id=%s',[id])
|
|
|
|
|
return render_template('show.html', parent=parent, cursor=cursor)
|
|
|
|
|
|