def full_recipe(recipe_id): """ Page showing full recipe info """ db = get_recipe_db() recipe = db.get_recipe(recipe_id) html_ingredients = process_markdown(recipe.ingredients) html_instructions = process_markdown(recipe.instructions) return render_template('recipes/full_recipe.html', recipe=recipe, ingredients=html_ingredients, instructions=html_instructions)
def render_recipe_editor(recipe_id=None): """ Render recipe editor page. If recipe_id is supplied, uses that recipe to populate form (edit recipe), otherwise form is blank (new recipe) """ db = get_recipe_db() if recipe_id is None: recipe = RecipeEntry(id=-1, name='', description='', type_id=-1) else: recipe = db.get_recipe(recipe_id) food_types = db.get_all_types() return render_template('recipes/edit_recipe.html', recipe=recipe, food_types=food_types)
def validate_and_post_changes(recipe_id=None): """ Post changes to recipe, returns recipe_id """ db = get_recipe_db() recipe = RecipeEntry(id=recipe_id, name=request.form['name'], description=request.form['description'], type_id=request.form['food_type']) recipe.ingredients = bleach.clean(request.form['ingredients']) recipe.instructions = bleach.clean(request.form['instructions']) if not recipe.name: raise UserInputError('Recipe name is required.') if not db.get_food_type(recipe.type_id): raise UserInputError('Unknown food category.') if recipe_id is None: recipe_id = db.add_recipe(recipe) else: db.update_recipe(recipe) return recipe_id
def index(): """ Index page showing list of recipes """ db = get_recipe_db() recipes = db.get_all_recipes() return render_template('recipes/index.html', recipes=recipes)
def delete(recipe_id): """ POST: delete recipe from database """ db = get_recipe_db() db.delete_recipe(recipe_id) return redirect(url_for('recipes.index'))