Commit efed3abe authored by Francesca Sargent 's avatar Francesca Sargent
Browse files

Smoothing out Integrity Error

parent de36a9f5
......@@ -80,8 +80,11 @@ def poststuff(type):
if current_user.can(Permission.WRITE_ARTICLES) and \
form.validate_on_submit():
methods = [Method(name=form.methods.data, timestamp='now', author=current_user._get_current_object())]
if Method.query.filter_by(name=form.methods.data).first() is None:
methods = [Method(name=form.methods.data, timestamp='now', author=current_user._get_current_object())]
else:
methods = [Method.query.filter_by(name=form.methods.data).first()]
cuisine = Cuisine(name=form.name.data, description=form.description.data,
methods=methods,
author=current_user._get_current_object())
......@@ -94,7 +97,10 @@ def poststuff(type):
if current_user.can(Permission.WRITE_ARTICLES) and \
form.validate_on_submit():
cuisines = [Cuisine(name=form.cuisines.data, timestamp='now', author=current_user._get_current_object())]
if Cuisine.query.filter_by(name=form.cuisines.data).first() is None:
cuisines = [Cuisine(name=form.cuisines.data, timestamp='now', author=current_user._get_current_object())]
else:
cuisines = [Cuisine.query.filter_by(name=form.cuisines.data).first()]
method = Method(
name=form.name.data,
......@@ -307,7 +313,10 @@ def editmethod(id):
form = MethodForm()
if form.validate_on_submit():
cuisines = [Cuisine(name=form.cuisines.data, timestamp='now', author=current_user._get_current_object())]
if Cuisine.query.filter_by(name=form.cuisines.data).first() is None:
cuisines = [Cuisine(name=form.cuisines.data, timestamp='now', author=current_user._get_current_object())]
else:
cuisines = [Cuisine.query.filter_by(name=form.cuisines.data).first()]
method.name = form.name.data
method.description = form.description.data
......@@ -335,7 +344,10 @@ def editcuisine(id):
cuisine.name = form.name.data
cuisine.description = form.description.data
methods = [Method(name=form.methods.data, author=current_user._get_current_object())]
if Method.query.filter_by(name=form.methods.data).first() is None:
methods = [Method(name=form.methods.data, timestamp='now', author=current_user._get_current_object())]
else:
methods = [Method.query.filter_by(name=form.methods.data).first()]
cuisine.methods.extend(methods)
db.session.add(cuisine)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment