improved DB error handling
This commit is contained in:
12
condition.py
12
condition.py
@@ -47,8 +47,9 @@ def conditions():
|
||||
@app.route("/condition", methods=["GET", "POST"])
|
||||
def new_condition():
|
||||
form = ConditionForm(request.form)
|
||||
page_title='Create new Condition'
|
||||
if 'name' not in request.form:
|
||||
return render_template("edit_id_name.html", form=form, page_title='Create new Condition' )
|
||||
return render_template("edit_id_name.html", form=form, page_title=page_title )
|
||||
else:
|
||||
condition = Condition( name=request.form["name"] )
|
||||
try:
|
||||
@@ -59,7 +60,7 @@ def new_condition():
|
||||
except SQLAlchemyError as e:
|
||||
st.SetAlert( "danger" )
|
||||
st.SetMessage( "<b>Failed to add condition:</b> {}".format( e.orig) )
|
||||
return render_template("edit_id_name.html", form=form, page_title='Create new Condition', alert=st.GetAlert(), message=st.GetMessage() )
|
||||
return render_template("edit_id_name.html", form=form, page_title=page_title, alert=st.GetAlert(), message=st.GetMessage() )
|
||||
|
||||
################################################################################
|
||||
# /condition/<id> -> GET/POST(save or delete) -> shows/edits/delets a single condition
|
||||
@@ -68,6 +69,7 @@ def new_condition():
|
||||
def condition(id):
|
||||
### DDP: should this be request.form or request.values?
|
||||
form = ConditionForm(request.form)
|
||||
page_title='Edit Condition'
|
||||
if request.method == 'POST' and form.validate():
|
||||
try:
|
||||
condition = Condition.query.get(id)
|
||||
@@ -81,12 +83,12 @@ def condition(id):
|
||||
return redirect( '/conditions' )
|
||||
except SQLAlchemyError as e:
|
||||
st.SetAlert( "danger" )
|
||||
st.SetMessage( "<b>Failed to modity condition:</b> {}".format(e.orig) )
|
||||
return render_template("edit_id_name.html", form=form, page_title='Edit Condition', alert=st.GetAlert(), message=st.GetMessage() )
|
||||
st.SetMessage( "<b>Failed to modify Condition:</b> {}".format(e.orig) )
|
||||
return render_template("edit_id_name.html", form=form, page_title=page_title, alert=st.GetAlert(), message=st.GetMessage() )
|
||||
else:
|
||||
condition = Condition.query.get(id)
|
||||
form = ConditionForm(request.values, obj=condition)
|
||||
return render_template("edit_id_name.html", form=form, page_title='Edit Condition' )
|
||||
return render_template("edit_id_name.html", form=form, page_title=page_title )
|
||||
|
||||
################################################################################
|
||||
# Gets the Condition matching id from DB, helper func in jinja2 code to show books
|
||||
|
||||
Reference in New Issue
Block a user