Esempio n. 1
0
def index():
  recipe_form = RecipeForm(csrf_enabled=False)
  if recipe_form.validate_on_submit():
    new_id = len(recipes)+1
    recipes[new_id] = recipe_form.recipe.data
    types[new_id] = recipe_form.recipe_type.data
    descriptions[new_id] = recipe_form.description.data
    new_igredients = recipe_form.ingredients.data
    new_instructions = recipe_form.instructions.data
    add_ingredients(new_id, new_igredients)
    add_instructions(new_id, new_instructions)
    comments[new_id] = []
    #### Redirect to recipe route here
    return redirect(url_for("recipe", id=new_id, _external=True, _scheme='https'))
  return render_template("index.html", template_recipes=recipes, template_form=recipe_form)


# Review

# How to access form data using the request object
# Control path selection with route function names using url_for()
# Create a web form structure using FlaskForm and WTForm fields
# Create a web form in the templates using FlaskForm variables
# Utilize field validators for increased data integrity
# Use redirect() to change paths easily within the app
Esempio n. 2
0
def index():
  recipe_form = RecipeForm(csrf_enabled=False)
  if recipe_form.validate_on_submit():
    new_id = len(recipes)+1
    recipes[new_id] = recipe_form.recipe.data
    types[new_id] = recipe_form.recipe_type.data
    descriptions[new_id] = recipe_form.description.data
    new_igredients = recipe_form.ingredients.data
    new_instructions = recipe_form.instructions.data
    add_ingredients(new_id, new_igredients)
    add_instructions(new_id, new_instructions)
    "I'm not sure why Codecademy added the following line for the '/' route, when comments aren't utilized"
    #comments[new_id] = []

    """
    When the new recipe is added, the browswe redirects to the newly added recipe's page
    """
    
    return redirect(
      url_for(
        "recipe",
        id = new_id,
        _external = True,
        _scheme="https"
      )
    )

  return render_template("index.html", template_recipes=recipes, template_form=recipe_form)
Esempio n. 3
0
def index():
  new_id = len(recipes) + 1
  if len(request.form) > 0:
    #### Add the recipe name to recipes[new_id] 
    recipes[new_id] = request.form["recipe"]
    #### Add the recipe description to descriptions[new_id]
    descriptions[new_id] = request.form["description"]
    #### Add the values to new_ingredients and new_instructions
    new_ingredients = request.form["ingredients"]
    new_instructions = request.form["instructions"]
    add_ingredients(new_id, new_ingredients)
    add_instructions(new_id, new_instructions)
  return render_template("index.html", template_recipes=recipes)
Esempio n. 4
0
def index():
  recipe_form = RecipeForm(csrf_enabled=False)
  if recipe_form.validate_on_submit():
    new_id = len(recipes)+1
    recipes[new_id] = recipe_form.recipe.data
    #### Add type data here
    types[new_id] = recipe_form.recipe_type.data 
    descriptions[new_id] = recipe_form.description.data
    new_ingredients = recipe_form.ingredients.data
    new_instructions = recipe_form.instructions.data
    add_ingredients(new_id, new_ingredients)
    add_instructions(new_id, new_instructions)
    comments[new_id] = []
  return render_template("index.html", template_recipes=recipes, template_form=recipe_form)
Esempio n. 5
0
def index():
    recipe_form = RecipeForm()
    if recipe_form.validate_on_submit():
        new_id = len(recipes) + 1
        recipes[new_id] = recipe_form.recipe.data
        types[new_id] = recipe_form.recipe_type.data
        descriptions[new_id] = recipe_form.description.data
        new_ingredients = recipe_form.ingredients.data
        new_instructions = recipe_form.instructions.data
        add_ingredients(new_id, new_ingredients)
        add_instructions(new_id, new_instructions)
        comments[new_id] = []
        #### Redirect to recipe route here
        return redirect(url_for('recipe', id=new_id))
    return render_template("index.html",
                           template_recipes=recipes,
                           template_form=recipe_form)
Esempio n. 6
0
def index():
    recipe_form = RecipeForm(csrf_enabled=False)
    if recipe_form.validate_on_submit():
        new_id = len(recipes) + 1
        recipes[new_id] = recipe_form.recipe.data
        types[new_id] = recipe_form.recipe_type.data
        descriptions[new_id] = recipe_form.description.data
        new_igredients = recipe_form.ingredients.data
        new_instructions = recipe_form.instructions.data
        add_ingredients(new_id, new_igredients)
        add_instructions(new_id, new_instructions)
        comments[new_id] = []
        return redirect(
            url_for("recipe", id=new_id, _external=True, _scheme='https'))
    return render_template("index.html",
                           template_recipes=recipes,
                           template_form=recipe_form)
Esempio n. 7
0
def index():
    recipe_form = RecipeForm(request.form, meta={'csrf': False})
    if recipe_form.validate_on_submit():
        new_id = len(recipes) + 1
        recipes[new_id] = recipe_form.recipe.data
        types[new_id] = recipe_form.recipe_type.data
        descriptions[new_id] = recipe_form.description.data
        new_igredients = recipe_form.ingredients.data
        new_instructions = recipe_form.instructions.data
        add_ingredients(new_id, new_igredients)
        add_instructions(new_id, new_instructions)
        comments[new_id] = []
        #### Redirect to recipe route here
        return redirect(
            url_for("recipe", id=new_id, _external=True, _scheme='http'))
    return render_template("index.html",
                           template_recipes=recipes,
                           template_form=recipe_form)