|
|
|
@ -1,7 +1,9 @@
|
|
|
|
from flask import Flask, render_template, request, redirect
|
|
|
|
from flask import Flask, render_template, request, redirect, make_response
|
|
|
|
import mysql.connector
|
|
|
|
import mysql.connector
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: add breadcrumb
|
|
|
|
|
|
|
|
|
|
|
|
mydb = mysql.connector.connect(
|
|
|
|
mydb = mysql.connector.connect(
|
|
|
|
host=os.environ.get("HOST"),
|
|
|
|
host=os.environ.get("HOST"),
|
|
|
|
user=os.environ.get("USER"),
|
|
|
|
user=os.environ.get("USER"),
|
|
|
|
@ -15,7 +17,10 @@ app = Flask(__name__)
|
|
|
|
@app.get("/")
|
|
|
|
@app.get("/")
|
|
|
|
def show_all():
|
|
|
|
def show_all():
|
|
|
|
cursor.execute('SELECT * FROM items WHERE parent_id IS NULL')
|
|
|
|
cursor.execute('SELECT * FROM items WHERE parent_id IS NULL')
|
|
|
|
return render_template('show.html', cursor=cursor)
|
|
|
|
if request.cookies.get('movingItemId'):
|
|
|
|
|
|
|
|
return render_template('show.html', cursor=cursor, moving_item_id=request.cookies.get('movingItemId'))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return render_template('show.html', cursor=cursor)
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/")
|
|
|
|
@app.post("/")
|
|
|
|
def create():
|
|
|
|
def create():
|
|
|
|
@ -32,9 +37,8 @@ def create():
|
|
|
|
)
|
|
|
|
)
|
|
|
|
return redirect('/')
|
|
|
|
return redirect('/')
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/<id>")
|
|
|
|
@app.post("/<int:id>")
|
|
|
|
def deleteUpdate(id):
|
|
|
|
def deleteUpdate(id):
|
|
|
|
print(request.args.get('_method'))
|
|
|
|
|
|
|
|
# TODO: deal with deleting item that has children
|
|
|
|
# TODO: deal with deleting item that has children
|
|
|
|
if request.args.get('_method') == 'DELETE':
|
|
|
|
if request.args.get('_method') == 'DELETE':
|
|
|
|
cursor.execute('DELETE FROM items WHERE id=%s LIMIT 1', [id])
|
|
|
|
cursor.execute('DELETE FROM items WHERE id=%s LIMIT 1', [id])
|
|
|
|
@ -53,9 +57,28 @@ def show(id):
|
|
|
|
cursor.execute('SELECT * FROM items WHERE id=%s', [id])
|
|
|
|
cursor.execute('SELECT * FROM items WHERE id=%s', [id])
|
|
|
|
parent=cursor.fetchone()
|
|
|
|
parent=cursor.fetchone()
|
|
|
|
cursor.execute('SELECT * FROM items WHERE parent_id=%s',[id])
|
|
|
|
cursor.execute('SELECT * FROM items WHERE parent_id=%s',[id])
|
|
|
|
return render_template('show.html', parent=parent, cursor=cursor)
|
|
|
|
if request.cookies.get('movingItemId'):
|
|
|
|
|
|
|
|
return render_template('show.html', parent=parent, cursor=cursor, moving_item_id=request.cookies.get('movingItemId'))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return render_template('show.html', parent=parent, cursor=cursor)
|
|
|
|
|
|
|
|
|
|
|
|
@app.get('/<id>/edit')
|
|
|
|
@app.get('/<id>/edit')
|
|
|
|
def edit(id):
|
|
|
|
def edit(id):
|
|
|
|
cursor.execute('SELECT * FROM items WHERE id=%s', [id])
|
|
|
|
cursor.execute('SELECT * FROM items WHERE id=%s', [id])
|
|
|
|
return render_template('edit.html', item=cursor.fetchone())
|
|
|
|
return render_template('edit.html', item=cursor.fetchone())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.post('/<id>/move')
|
|
|
|
|
|
|
|
@app.post('/move')
|
|
|
|
|
|
|
|
def move(id=None):
|
|
|
|
|
|
|
|
if request.args.get('_method') == 'PUT':
|
|
|
|
|
|
|
|
cursor.execute('UPDATE items SET parent_id = %s WHERE id = %s LIMIT 1', [id if id else None, request.cookies.get('movingItemId')])
|
|
|
|
|
|
|
|
response = make_response(redirect('/' + id))
|
|
|
|
|
|
|
|
response.set_cookie('movingItemId', '', expires = 0)
|
|
|
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
if 'parent_id' in request.form:
|
|
|
|
|
|
|
|
response = make_response(redirect('/'+request.form['parent_id']))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
response = make_response(redirect('/'))
|
|
|
|
|
|
|
|
response.set_cookie('movingItemId', id)
|
|
|
|
|
|
|
|
return response
|
|
|
|
|