From 0a6f6308c13c3b93feb09348f0fb170098c1ddf3 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 4 Oct 2019 16:56:06 +0100 Subject: [PATCH] More checks before save. --- app.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app.py b/app.py index 4996d52..420b868 100755 --- a/app.py +++ b/app.py @@ -188,6 +188,10 @@ def user_settings(): return 'flipped. find more is ' + display +def no_existing_edit(item_id, depicts_id): + q = Edit.query.filter(painting_id=item_id, depicts_id=depicts_id) + return q.count() == 0 + @app.route('/save/Q', methods=['POST']) def save(item_id): depicts = request.form.getlist('depicts') @@ -213,6 +217,10 @@ def save(item_id): database.session.add(depicts_item) database.session.commit() + assert no_existing_edit(item_id, depicts_id) + + for depicts_qid in depicts: + depicts_id = int(depicts_qid[1:]) r = create_claim(item_id, depicts_id, token) reply = r.json() if 'error' in reply: