convert checkboxes to boolean before saving
This commit is contained in:
parent
312ad3d93d
commit
511799f85b
|
|
@ -5,6 +5,8 @@ table_name = 'conditions'
|
||||||
route = table_name
|
route = table_name
|
||||||
r = getRethinkDB()
|
r = getRethinkDB()
|
||||||
|
|
||||||
|
booleans = ["disbled"]
|
||||||
|
|
||||||
def create_conditions_routes(app):
|
def create_conditions_routes(app):
|
||||||
# Create a table (if not exists)
|
# Create a table (if not exists)
|
||||||
if table_name not in r.table_list().run(get_connection()):
|
if table_name not in r.table_list().run(get_connection()):
|
||||||
|
|
@ -24,6 +26,10 @@ def create_conditions_routes(app):
|
||||||
else: # Assuming form data is in 'application/x-www-form-urlencoded' format
|
else: # Assuming form data is in 'application/x-www-form-urlencoded' format
|
||||||
data = request.form.to_dict()
|
data = request.form.to_dict()
|
||||||
|
|
||||||
|
# convert checkboxes to true/false
|
||||||
|
for key in booleans:
|
||||||
|
data[key] = key in request.form
|
||||||
|
|
||||||
result = r.table(table_name).insert(data).run(get_connection())
|
result = r.table(table_name).insert(data).run(get_connection())
|
||||||
return render_template(route + '/create.html')
|
return render_template(route + '/create.html')
|
||||||
|
|
||||||
|
|
@ -50,6 +56,11 @@ def create_conditions_routes(app):
|
||||||
data = request.json
|
data = request.json
|
||||||
else:
|
else:
|
||||||
data = request.form.to_dict()
|
data = request.form.to_dict()
|
||||||
|
|
||||||
|
# convert checkboxes to true/false
|
||||||
|
for key in booleans:
|
||||||
|
data[key] = key in request.form
|
||||||
|
|
||||||
r.table(table_name).get(id).update(data).run(get_connection())
|
r.table(table_name).get(id).update(data).run(get_connection())
|
||||||
return "<script>window.close();</script>"
|
return "<script>window.close();</script>"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue