Commit 3457c7bf authored by Francesca Sargent 's avatar Francesca Sargent
Browse files

Editing Methods via Cuisine

parent 4029a051
......@@ -71,10 +71,6 @@ def poststuff(type):
recipe = Recipe(
name=form.name.data,
description=form.description.data,
# cuisine=form.cuisine.data,
# cuisines = [Cuisine.query \
# .filter(Cuisine.name == form.cuisine.data) \
# .first()],
author=current_user._get_current_object())
db.session.add(recipe)
return redirect(url_for('.index'))
......@@ -97,12 +93,17 @@ def poststuff(type):
form = MethodForm()
if current_user.can(Permission.WRITE_ARTICLES) and \
form.validate_on_submit():
cuisines = Cuisine(name=form.methods.data, timestamp='now', author=current_user._get_current_object())]
method = Method(
name=form.name.data,
description=form.description.data,
method_text=form.method_text.data,
cuisines = cuisines,
author=current_user._get_current_object())
db.session.add(method)
db.session.flush()
return redirect(url_for('.index'))
db.session.commit()
......@@ -279,6 +280,7 @@ def method(id):
@main.route('/recipe/<int:id>/edit', methods=['GET', 'POST'])
@login_required
def editrecipe(id):
db.session.autoflush = True
recipe = Recipe.query.get_or_404(id)
if current_user != recipe.author and \
not current_user.can(Permission.ADMINISTER):
......@@ -297,14 +299,19 @@ def editrecipe(id):
@main.route('/method/<int:id>/edit', methods=['GET', 'POST'])
@login_required
def editmethod(id):
db.session.autoflush = True
method = Method.query.get_or_404(id)
if current_user != method.author and \
not current_user.can(Permission.ADMINISTER):
abort(403)
form = MethodForm()
if form.validate_on_submit():
cuisines = Cuisine(name=form.methods.data, timestamp='now', author=current_user._get_current_object())]
method.name = form.name.data
method.description = form.description.data
method.cuisines.extend(cuisines)
method.method_text = form.method_text.data
db.session.add(method)
flash('The method has been updated.')
......@@ -317,6 +324,7 @@ def editmethod(id):
@main.route('/cuisine/<int:id>/edit', methods=['GET', 'POST'])
@login_required
def editcuisine(id):
db.session.autoflush = True
cuisine = Cuisine.query.get_or_404(id)
if current_user != cuisine.author and \
not current_user.can(Permission.ADMINISTER):
......
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