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,16 +47,21 @@ 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 cursor.execute(
if request.args.get('_method') == 'DELETE': 'UPDATE items SET title=%s, description=%s, parent_id=%s WHERE id=%s',
cursor.execute('DELETE FROM items WHERE id=%s LIMIT 1', [id]) [request.form['title'], request.form['description'], request.form['parent_id'] if request.form['parent_id'] != '' else None, id]
)
if 'parent_id' in request.form:
return redirect('/'+request.form['parent_id'])
else: else:
cursor.execute( return redirect('/')
'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] @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: if 'parent_id' in request.form:
return redirect('/'+request.form['parent_id']) return redirect('/'+request.form['parent_id'])
else: else:

Loading…
Cancel
Save