def addRecipe(img_file, title, description, cat_code, servings, cooktime,
              skillLevel, cuisine, ingredients, steps, user):
    """ It adds a recipe, ingredients, recipe steps, recipe_user"""

    try:
        # Saves the img file in the directory
        filename = img_file

        print "IMG_FILE", img_file

        # If img is not from a website
        # if img_file and allowed_file(img_file.filename) and 'http' not in img_file:

        #     filename = secure_filename(img_file.filename)
        # print "FILENAME" , filename
        # img_file.save(os.path.join(UPLOAD_FOLDER, filename))

        # Add recipe in 'recipes' Table
        Recipe.addRecipe(title, description, filename, cat_code, servings,
                         cooktime, skillLevel, cuisine)

        # Finds the recipe_id
        recipeIds = db.session.query(func.max(Recipe.recipe_id)).one()
        recipeFk = recipeIds[0]
        print "RECIPE ID:  ", recipeFk

        # ingredients = ingredients
        print "INGREDIENTS LIST", ingredients

        for ingredient in ingredients:
            name = ingredient["name"]
            qty = ingredient["qty"]
            unit = ingredient["unit"]
            print "INGREDIENT UNICODE", ingredient

            # Add ingredients in 'RecipeIngredient'
            RecipeIngredient.addIngredients(recipeFk, name, qty, unit)
            # Add ingredients in 'Ingredients'
            Ingredient.addIngredients(name)

        for i in range(len(steps)):
            print "STEP%d" % i
            print "step value: ", steps[i]
            # Add steps in 'recipe_step'
            RecipeStep.addRecipeStep(recipeFk, i + 1, steps[i])

        if 'User' in session:
            RecipeUser.addRecipeForUser(recipeFk, session['User'])

        db.session.commit()

        # Recipe.updateRecipeImg(title=title, cat_code=cat_code)

        message = {'msg': "Recipe successfully added", 'recipeid': recipeFk}

        return recipeFk

    except Exception, error:
        return "Error: %s" % error
def addRecipe(img_file, title, description, cat_code, servings,
             cooktime, skillLevel, cuisine, ingredients, steps, user):

    """ It adds a recipe, ingredients, recipe steps, recipe_user"""

    try:
        # Saves the img file in the directory
        filename = img_file

        print "IMG_FILE" ,img_file

        # If img is not from a website
        # if img_file and allowed_file(img_file.filename) and 'http' not in img_file:

        #     filename = secure_filename(img_file.filename)
            # print "FILENAME" , filename
            # img_file.save(os.path.join(UPLOAD_FOLDER, filename))

        # Add recipe in 'recipes' Table
        Recipe.addRecipe(title, description, filename, cat_code,
                 servings, cooktime, skillLevel,cuisine)

        # Finds the recipe_id
        recipeIds= db.session.query(func.max(Recipe.recipe_id)).one()
        recipeFk = recipeIds[0]
        print "RECIPE ID:  ",recipeFk

        # ingredients = ingredients
        print "INGREDIENTS LIST", ingredients

        for ingredient in ingredients:
            name = ingredient["name"]
            qty = ingredient["qty"]
            unit = ingredient["unit"]
            print "INGREDIENT UNICODE", ingredient

            # Add ingredients in 'RecipeIngredient'
            RecipeIngredient.addIngredients(recipeFk, name, qty, unit)
            # Add ingredients in 'Ingredients'
            Ingredient.addIngredients(name)


        for i in range(len(steps)):
            print "STEP%d" % i
            print "step value: ", steps[i]
            # Add steps in 'recipe_step'
            RecipeStep.addRecipeStep(recipeFk,i+1,steps[i])

        if 'User' in session:
            RecipeUser.addRecipeForUser(recipeFk,session['User'])

        db.session.commit()

        # Recipe.updateRecipeImg(title=title, cat_code=cat_code)

        message = {

            'msg': "Recipe successfully added",
            'recipeid': recipeFk
        }

        return recipeFk

    except Exception, error:
        return "Error: %s" % error