splitting delete/update

master
Matt Huntington 3 years ago
parent df453940d1
commit 2022eb40b3

@ -24,10 +24,6 @@ cursor = mydb.cursor()
app = Flask(__name__) app = Flask(__name__)
app.wsgi_app = HTTPMethodOverrideMiddleware(app.wsgi_app) app.wsgi_app = HTTPMethodOverrideMiddleware(app.wsgi_app)
@app.put('/')
def test():
return 'hi'
@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')
@ -51,12 +47,8 @@ def create():
) )
return redirect('/') return redirect('/')
@app.post("/<int:id>") @app.put("/<int:id>")
def deleteUpdate(id): def deleteUpdate(id):
# TODO: deal with deleting item that has children
if request.args.get('_method') == 'DELETE':
cursor.execute('DELETE FROM items WHERE id=%s LIMIT 1', [id])
else:
cursor.execute( cursor.execute(
'UPDATE items SET title=%s, description=%s, parent_id=%s WHERE id=%s', 'UPDATE items SET title=%s, description=%s, parent_id=%s WHERE id=%s',
[request.form['title'], request.form['description'], request.form['parent_id'] if request.form['parent_id'] != '' else None, id] [request.form['title'], request.form['description'], request.form['parent_id'] if request.form['parent_id'] != '' else None, id]
@ -66,6 +58,15 @@ def deleteUpdate(id):
else: else:
return redirect('/') return redirect('/')
@app.delete('/<int:id>')
def delete(id):
# TODO: deal with deleting item that has children
cursor.execute('DELETE FROM items WHERE id=%s LIMIT 1', [id])
if 'parent_id' in request.form:
return redirect('/'+request.form['parent_id'])
else:
return redirect('/')
@app.get("/<id>") @app.get("/<id>")
def show(id): def show(id):
cursor.execute('SELECT * FROM items WHERE id=%s', [id]) cursor.execute('SELECT * FROM items WHERE id=%s', [id])

Loading…
Cancel
Save