Ejemplo n.º 1
0
def send_recipe(user_recipe, username):
    user = User.query.filter_by(username=username).first()
    methods = user_recipe.getlist('step')
    methodNumber = 1
    ingredNumber = 1

    recipe = Recipe(name=user_recipe['name'],
                    description=user_recipe['description'],
                    cookingtime=user_recipe['cookingtime'],
                    servings=user_recipe['servings'],
                    course=user_recipe['course'],
                    countryOfOrigin=user_recipe['origin'],
                    user_id=user.userId)
    db.session.add(recipe)

    recipe.methods = []

    for method in methods:
        method1 = Method(stepNumber=methodNumber, description=method)
        recipe.methods.append(method1)
        methodNumber += 1

    recipe.ingredients = []
    ingredients = user_recipe['ingredients-list'].split(',')

    for ingredient in ingredients:
        ingredient1 = Ingredient(name=ingredient)
        recipe.ingredients.append(ingredient1)
        ingredNumber += 1

    db.session.commit()
Ejemplo n.º 2
0
def add_recipe():
    body = json.loads(request.data)
    name = body.get('name')

    if name is None:
        return failure_response("Incorrect input!")
    new_recipe = Recipe(name=name)
    db.session.add(new_recipe)
    db.session.commit()
    return success_response(new_recipe.simple_serialize(), 201)
Ejemplo n.º 3
0
def newRecipe(cuisine_entries):
    """This endpoint adds a new recipe into database. In order to
    execute this endpoint, user must be logged in.
    """
    if request.method == 'GET':
        user = session.get('username', None)
        return render_template(
            'layout.html',
            user=user,
            new_recipe=True,
            cuisines=cuisine_entries)

    if request.method == 'POST' and 'recipe' in request.form:
        email = session.get('email', None)
        cuisine_name = request.form['cuisine']
        cuisine = session_db.query(Cuisine).filter_by(
            name=cuisine_name).one_or_none()
        user = session_db.query(Users).filter_by(email=email).one_or_none()

        recipe = Recipe(
            name=request.form['name'],
            cuisine_id=cuisine.id,
            ingredients=request.form['ingredients'],
            body=request.form['recipe'],
            user_id=user.id,
            created=datetime.datetime.now()
        )

        session_db.add(recipe)
        session_db.commit()
        flash('Recipe has been created')
        return redirect(url_for('index'))
Ejemplo n.º 4
0
def recipe_add():
    data = request.get_json(force=True)
    required_fields = ['title', 'images', 'difficulty', 'duration', 'steps']
    for required_field in required_fields:
        if not required_field in data:
            abort(400)
    recipe = Recipe(data['title'], data['difficulty'], data['duration'],
                    data['images'], data['steps'])
    db.session.add(recipe)
    db.session.commit()
Ejemplo n.º 5
0
async def create_recipe(recipe_in: RecipeIn, db: Session = Depends(get_db)):
    recipe = Recipe(title=recipe_in.title,
                    making_time=recipe_in.making_time,
                    serves=recipe_in.serves,
                    ingredients=recipe_in.ingredients,
                    cost=recipe_in.cost)
    db.add(recipe)
    db.commit()
    recipe = get_recipe(db, recipe.id)
    return recipe
Ejemplo n.º 6
0
def index(cuisine, cuisine_entries):
    if request.method == 'GET':
        recipes = []
        query = session_db.query(Recipe)\
            .join(Recipe.cuisine)\
            .order_by(asc(Recipe.created))
        if cuisine == 'all':
            recipes = query.all()
        else:
            recipes = query.filter(Cuisine.name == cuisine).all()

        user = session.get('username', None)
        return render_template('layout.html',
                               index=True,
                               cuisine_entries=cuisine_entries,
                               this_cuisine=cuisine,
                               recipes=recipes,
                               user=user)
    elif request.method == 'POST' and 'recipe' in request.form:
        cuisine_name = cuisine
        if cuisine_name.lower() == 'all':
            cuisine_name = 'no-cuisine'

        cuisine_entry = session_db.query(cuisines)\
            .filter_by(name=cuisine_name)\
            .one()

        user_id = None
        email = session.get('email')
        if email:
            user = session_db.query(Users)\
                .filter_by(email=email)\
                .first()
            if user:
                user_id = user.id
        recipe = Recipe(body=request.form['recipe'],
                        created=datetime.datetime.now(),
                        cuisine_id=cuisine_entry.id,
                        user_id=user_id or 1)
        session_db.add(recipe)
        session_db.commit()
        return redirect(url_for('show-cuisine', cuisine=cuisine))
recipe = Recipe(
    name="Chicken Tikka Masala",
    ingredients="""
    7 garlic cloves, finely grated 4 tsp
    finely grated peeled ginger 4 tsp
    ground turmeric 2 tsp
    garam masala 2 tsp
    ground coriander 2 tsp
    ground cumin 1-1/2 cups whole-milk yogurt (not Greek) 1 Tbsp
    kosher salt 2 lb
    skinless, boneless chicken breasts, halved lengthwise 3 Tbsp
    ghee (clarified butter) or vegetable oil 1 small onion, thinly
    sliced 1/4 cup tomato paste 6 cardamom pods, crushed 2 dried chiles,
    1/2 tsp crushed red pepper flakes
    can whole peeled tomatoes, 2 cups heavy cream 3/4 cup chopped cilantro,
    plus sprigs for garnish Steamed basmati rice (for serving)
""",
    body="""Combine garlic, ginger, turmeric, garam masala, coriander,
    and cumin in a small bowl. Whisk yogurt, salt,
    and half of spice mixture in a medium bowl; add chicken and turn to coat.
    Cover and chill 4-6 hours. Cover and chill remaining spice mixture.
    Heat ghee in a large heavy pot over medium heat. Add onion, tomato paste,
    cardamom, and chiles and cook, stirring often, until tomato paste has
    darkened and onion is soft, about 5 minutes. Add remaining half of spice
    mixture and cook, stirring often, until bottom of pot begins to brown,
    about 4 minutes.
""",
    user_id=this_user.id,
    cuisine_id=1,
    created=datetime.datetime.now())
session.add(recipe)
Ejemplo n.º 8
0
def delete_recipes(id):
    jsonify({"n": Recipe.delete().where(Recipe.id==id).execute()})
    return redirect('/recipe')
Ejemplo n.º 9
0
def get_recipes():
    recipes = []
    for recipe in Recipe.select():
        recipes.append(recipe.to_dictionary())
    return render_template('recipes.html', recipes=recipes)
Ejemplo n.º 10
0
def add_recipe():
    recipe = Recipe(name=request.form["name"], category=request.form["category"])
    recipe.save()
    return redirect('/recipe')