Exemple #1
0
def ingredients():
    # Query the ingredients data
    ingredients = db2.query(Ingredient).all()
    # Generate form to add ingredients
    form = IngredientForm(request.form)

    if form.validate_on_submit():
        new_ingredient = Ingredient(name=form.ingredient.data.strip().lower())
        new_ingredient.type = db2.query(Type).filter(
            Type.type == form.type.data).one()
        db2.add(new_ingredient)
        db2.commit()
        flash(('Successfully added ' + form.ingredient.data.strip().lower()),
              "success")
        return redirect(url_for('ingredients'))

    return render_template("ingredients.html",
                           ingredients=ingredients,
                           form=form)
Exemple #2
0
    reader = csv.DictReader(file)

    # Insert records into Type
    types = reader.fieldnames[1:]
    types_dict = {}
    for item in types:
        types_dict[item] = Type(type=item)
        db.add(types_dict[item])
    db.commit()

    # Insert records into Ingredient
    for row in reader:
        for type in types:
            if row[type] == "TRUE":
                ingredient = Ingredient(name=row['name'])
                ingredient.type = types_dict[type]
                db.add(ingredient)
                db.commit()

with open(file_methods, 'r') as file:
    reader = list(csv.DictReader(file))

    # Insert records into Style
    styles = set()
    for row in reader:
        styles.add(row['style'])
    styles_dict = {}
    for item in styles:
        styles_dict[item] = Style(style=item)
        db.add(styles_dict[item])
    db.commit()