diff --git a/condition.py b/condition.py
index 9377688..12aec2a 100644
--- a/condition.py
+++ b/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( "Failed to add condition: {}".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/ -> 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( "Failed to modity condition: {}".format(e.orig) )
- return render_template("edit_id_name.html", form=form, page_title='Edit Condition', alert=st.GetAlert(), message=st.GetMessage() )
+ st.SetMessage( "Failed to modify Condition: {}".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
diff --git a/covertype.py b/covertype.py
index ff99c43..62d21bb 100644
--- a/covertype.py
+++ b/covertype.py
@@ -3,6 +3,7 @@ from flask import request, render_template, redirect
from flask_wtf import FlaskForm
from __main__ import db, app, ma
from sqlalchemy import func, Sequence
+from sqlalchemy.exc import SQLAlchemyError
from status import st, Status
################################################################################
@@ -46,14 +47,21 @@ def covertypes():
@app.route("/covertype", methods=["GET", "POST"])
def new_covertype():
form = CovertypeForm(request.form)
+ page_title='Create new Covertype'
if 'name' not in request.form:
- return render_template("edit_id_name.html", form=form, page_title='Create new Covertype' )
+ return render_template("edit_id_name.html", form=form, page_title=page_title )
else:
covertype = Covertype( name=request.form["name"] )
- db.session.add(covertype)
- db.session.commit()
- st.SetMessage( "Created new Covertype (id={})".format(covertype.id) )
- return redirect( '/covertypes' )
+ try:
+ db.session.add(covertype)
+ db.session.commit()
+ st.SetMessage( "Created new Covertype (id={})".format(covertype.id) )
+ return redirect( '/covertypes' )
+ except SQLAlchemyError as e:
+ st.SetAlert( "danger" )
+ st.SetMessage( "Failed to add covertype: {}".format( e.orig) )
+ return render_template("edit_id_name.html", form=form, page_title=page_title, alert=st.GetAlert(), message=st.GetMessage() )
+
################################################################################
# /covertype/ -> GET/POST(save or delete) -> shows/edits/delets a single covertype
@@ -62,20 +70,26 @@ def new_covertype():
def covertype(id):
### DDP: should this be request.form or request.values?
form = CovertypeForm(request.form)
+ page_title='Edit Covertype'
if request.method == 'POST' and form.validate():
- covertype = Covertype.query.get(id)
- if 'delete' in request.form:
- st.SetMessage("Successfully deleted (id={}, name={})".format( covertype.id, covertype.name ) )
- covertype = Covertype.query.filter(Covertype.id==id).delete()
- if 'submit' in request.form:
- st.SetMessage("Successfully Updated Covertype (id={})".format(id) )
- covertype.name = request.form['name']
- db.session.commit()
- return redirect( '/covertypes' )
+ try:
+ covertype = Covertype.query.get(id)
+ if 'delete' in request.form:
+ st.SetMessage("Successfully deleted (id={}, name={})".format( covertype.id, covertype.name ) )
+ covertype = Covertype.query.filter(Covertype.id==id).delete()
+ if 'submit' in request.form:
+ st.SetMessage("Successfully Updated Covertype (id={})".format(id) )
+ covertype.name = request.form['name']
+ db.session.commit()
+ return redirect( '/covertypes' )
+ except SQLAlchemyError as e:
+ st.SetAlert( "danger" )
+ st.SetMessage( "Failed to modify Covertype: {}".format(e.orig) )
+ return render_template("edit_id_name.html", form=form, page_title=page_title, alert=st.GetAlert(), message=st.GetMessage() )
else:
covertype = Covertype.query.get(id)
form = CovertypeForm(request.values, obj=covertype)
- return render_template("edit_id_name.html", form=form, page_title='Edit Covertype' )
+ return render_template("edit_id_name.html", form=form, page_title=page_title )
################################################################################
# Gets the Covertype matching id from DB, helper func in jinja2 code to show books
diff --git a/genre.py b/genre.py
index 832e71d..45ee4b7 100644
--- a/genre.py
+++ b/genre.py
@@ -47,8 +47,9 @@ def genres():
@app.route("/genre", methods=["GET", "POST"])
def new_genre():
form = GenreForm(request.form)
+ page_title='Create new Genre'
if 'name' not in request.form:
- return render_template("edit_id_name.html", form=form, page_title='Create new Genre' )
+ return render_template("edit_id_name.html", form=form, page_title=page_title )
else:
genre = Genre( name=request.form["name"] )
try:
@@ -59,7 +60,7 @@ def new_genre():
except SQLAlchemyError as e:
st.SetAlert( "danger" )
st.SetMessage( "Failed to add Genre: {}".format( e.orig) )
- return render_template("edit_id_name.html", form=form, page_title='Create new Genre', 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() )
################################################################################
# /genre/ -> GET/POST(save or delete) -> shows/edits/delets a single genre
@@ -68,6 +69,7 @@ def new_genre():
def genre(id):
### DDP: should this be request.form or request.values?
form = GenreForm(request.form)
+ page_title='Edit Genre'
if request.method == 'POST' and form.validate():
try:
genre = Genre.query.get(id)
@@ -81,12 +83,12 @@ def genre(id):
return redirect( '/genres' )
except SQLAlchemyError as e:
st.SetAlert( "danger" )
- st.SetMessage( "Failed to modity Genre: {}".format(e.orig) )
- return render_template("edit_id_name.html", form=form, page_title='Edit Genre', alert=st.GetAlert(), message=st.GetMessage() )
+ st.SetMessage( "Failed to modify Genre: {}".format(e.orig) )
+ return render_template("edit_id_name.html", form=form, page_title=page_title, alert=st.GetAlert(), message=st.GetMessage() )
else:
genre = Genre.query.get(id)
form = GenreForm(request.values, obj=genre)
- return render_template("edit_id_name.html", form=form, page_title='Edit Genre' )
+ return render_template("edit_id_name.html", form=form, page_title=page_title )
################################################################################
# Gets the Genre matching id from DB, helper func in jinja2 code to show books
diff --git a/owned.py b/owned.py
index 5591ef9..1e09093 100644
--- a/owned.py
+++ b/owned.py
@@ -3,6 +3,7 @@ from flask import request, render_template, redirect
from flask_wtf import FlaskForm
from __main__ import db, app, ma
from sqlalchemy import func, Sequence
+from sqlalchemy.exc import SQLAlchemyError
from status import st, Status
################################################################################
@@ -46,14 +47,20 @@ def owneds():
@app.route("/owned", methods=["GET", "POST"])
def new_owned():
form = OwnedForm(request.form)
+ page_title='Create new Ownership Type'
if 'name' not in request.form:
- return render_template("edit_id_name.html", form=form, page_title='Create new Owned Type' )
+ return render_template("edit_id_name.html", form=form, page_title=page_title )
else:
owned = Owned( name=request.form["name"] )
- db.session.add(owned)
- db.session.commit()
- st.SetMessage( "Created new Owned Type (id={})".format(owned.id) )
- return redirect( '/owneds' )
+ try:
+ db.session.add(owned)
+ db.session.commit()
+ st.SetMessage( "Created new Owned Type (id={})".format(owned.id) )
+ return redirect( '/owneds' )
+ except SQLAlchemyError as e:
+ st.SetAlert( "danger" )
+ st.SetMessage( "Failed to add Ownership type: {}".format( e.orig) )
+ return render_template("edit_id_name.html", form=form, page_title=page_title, alert=st.GetAlert(), message=st.GetMessage() )
################################################################################
# /owned/ -> GET/POST(save or delete) -> shows/edits/delets a single owned
@@ -63,15 +70,20 @@ def owned(id):
### DDP: should this be request.form or request.values?
form = OwnedForm(request.form)
if request.method == 'POST' and form.validate():
- owned = Owned.query.get(id)
- if 'delete' in request.form:
- st.SetMessage("Successfully deleted (id={}, name={})".format( owned.id, owned.name ) )
- owned = Owned.query.filter(Owned.id==id).delete()
- if 'submit' in request.form:
- owned.name = request.form['name']
- st.SetMessage("Successfully Updated Owned (id={})".format(id) )
- db.session.commit()
- return redirect( '/owneds' )
+ try:
+ owned = Owned.query.get(id)
+ if 'delete' in request.form:
+ st.SetMessage("Successfully deleted (id={}, name={})".format( owned.id, owned.name ) )
+ owned = Owned.query.filter(Owned.id==id).delete()
+ if 'submit' in request.form:
+ owned.name = request.form['name']
+ st.SetMessage("Successfully Updated Owned (id={})".format(id) )
+ db.session.commit()
+ return redirect( '/owneds' )
+ except SQLAlchemyError as e:
+ st.SetAlert( "danger" )
+ st.SetMessage( "Failed to modify Ownership Type: {}".format(e.orig) )
+ return render_template("edit_id_name.html", form=form, page_title='Edit Ownership Type', alert=st.GetAlert(), message=st.GetMessage() )
else:
obj = Owned.query.get(id)
form = OwnedForm(request.values, obj=obj)
diff --git a/rating.py b/rating.py
index e806bc8..4e70046 100644
--- a/rating.py
+++ b/rating.py
@@ -47,8 +47,9 @@ def ratings():
@app.route("/rating", methods=["GET", "POST"])
def new_rating():
form = RatingForm(request.form)
+ page_title='Create new Rating'
if 'name' not in request.form:
- return render_template("edit_id_name.html", form=form, page_title='Create new Rating' )
+ return render_template("edit_id_name.html", form=form, page_title=page_title )
else:
rating = Rating( name=request.form["name"] )
try:
@@ -59,7 +60,7 @@ def new_rating():
except SQLAlchemyError as e:
st.SetAlert( "danger" )
st.SetMessage( "Failed to add rating: {}".format( e.orig) )
- return render_template("edit_id_name.html", form=form, page_title='Create new Rating', 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() )
################################################################################
# /rating/ -> GET/POST(save or delete) -> shows/edits/delets a single rating
@@ -68,6 +69,7 @@ def new_rating():
def rating(id):
### DDP: should this be request.form or request.values?
form = RatingForm(request.form)
+ page_title='Edit Rating'
if request.method == 'POST' and form.validate():
try:
rating = Rating.query.get(id)
@@ -81,12 +83,12 @@ def rating(id):
return redirect( '/ratings' )
except SQLAlchemyError as e:
st.SetAlert( "danger" )
- st.SetMessage( "Failed to modity rating: {}".format(e.orig) )
- return render_template("edit_id_name.html", form=form, page_title='Edit Rating', alert=st.GetAlert(), message=st.GetMessage() )
+ st.SetMessage( "Failed to modify Rating: {}".format(e.orig) )
+ return render_template("edit_id_name.html", form=form, page_title=page_title, alert=st.GetAlert(), message=st.GetMessage() )
else:
rating = Rating.query.get(id)
form = RatingForm(request.values, obj=rating)
- return render_template("edit_id_name.html", form=form, page_title='Edit Rating' )
+ return render_template("edit_id_name.html", form=form, page_title=page_title )
################################################################################
# Gets the Rating matching id from DB, helper func in jinja2 code to show books