starting on update/delete db error handling, but not working yet

This commit is contained in:
2020-12-30 23:13:50 +11:00
parent 7691fd922f
commit ef852d52b0

View File

@@ -83,7 +83,9 @@ def new_series():
def series(id):
### DDP: should this be request.form or request.values?
form = SeriesForm(request.form)
page_title='Edit Series'
if request.method == 'POST' and form.validate():
try:
series = Series.query.get(id)
if 'delete' in request.form:
st.SetMessage("Successfully deleted (id={}, title={})".format( series.id, series.title ) )
@@ -96,10 +98,15 @@ def series(id):
series.note = request.form['note']
db.session.commit()
return redirect( '/seriess' )
except SQLAlchemyError as e:
print("series -- error!")
st.SetAlert( "danger" )
st.SetMessage( "<b>Failed to modify Series:</b>&nbsp;{}".format(e.orig) )
return render_template("edit_id_name.html", form=form, page_title=page_title, alert=st.GetAlert(), message=st.GetMessage() )
else:
series = Series.query.get(id)
form = SeriesForm(request.values, obj=series)
return render_template("series.html", form=form, page_title='Edit Series' )
return render_template("series.html", form=form, page_title=page_title )
################################################################################
# Gets the Series matching id from DB, helper func in jinja2 code to show books