Пример #1
0
def ingredients_save_edit(ingredient_id):
    form = NewIngredientForm(request.form)
    ingredient = Ingredient.query.get(ingredient_id)

    if not form.validate():
        return render_template("ingredients/edit.html",
                               form=form,
                               ingredient=ingredient)

    ingredient.name = form.name.data
    ingredient.unit = form.unit.data

    db.session().commit()

    return redirect(url_for("ingredients_index"))
Пример #2
0
def ingredients_create():
    form = NewIngredientForm(request.form)

    if not form.validate():
        return render_template("ingredients/new.html", form=form)

    name = str(form.name.data).capitalize()
    i = Ingredient(name, form.unit.data)

    if current_user is not None:
        i.account_id = current_user.id
        if current_user.role.name == "USER+" or current_user.role.name == "ADMIN":
            i.accepted = True

    db.session().add(i)
    db.session().commit()

    return redirect(url_for("ingredients_index"))
Пример #3
0
def ingredients_edit(ingredient_id):
    ingredient = Ingredient.query.get(ingredient_id)

    form = NewIngredientForm()
    form.name.data = ingredient.name
    form.unit.data = ingredient.unit

    return render_template("ingredients/edit.html",
                           form=form,
                           ingredient=ingredient)
Пример #4
0
def ingredients_edit(ingredient_id):
    try:
        int(ingredient_id)
    except:
        return render_template("ingredients/edit.html", form=None)

    ingredient = Ingredient.query.get(ingredient_id)

    if ingredient is None:
        return render_template("ingredients/edit.html", form=None)

    form = NewIngredientForm()
    form.name.data = ingredient.name
    form.unit.data = ingredient.unit

    return render_template("ingredients/edit.html",
                           form=form,
                           ingredient=ingredient)
Пример #5
0
def ingredients_form():
    return render_template("ingredients/new.html", form=NewIngredientForm())