You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

87 lines
2.5 KiB

from flask import Blueprint, render_template, request, redirect, url_for, current_app, send_from_directory,flash
from werkzeug.utils import secure_filename
from flask_login import login_user, logout_user, login_required, current_user
import os
from .models import db, Recipe, Ingredient, Instruction
bp = Blueprint("paginas", __name__)
@bp.route('/')
def index():
recipes = Recipe.query.all()
return render_template('index.html', recipes=recipes)
@bp.route('/recipe/<int:recipe_id>')
def recipe(recipe_id):
recipe = Recipe.query.get_or_404(recipe_id)
return render_template('recipe.html', recipe=recipe)
@bp.route('/new_recipe', methods=['GET', 'POST'])
@login_required
def new_recipe():
if request.method == 'POST':
title = request.form['title']
description = request.form['description']
ingredients = request.form.getlist('ingredient')
quantities = request.form.getlist('quantity')
steps = request.form.getlist('step')
step_descriptions = request.form.getlist('step_description')
recipe = Recipe(title=title, description=description, author=current_user)
for ingredient, quantity in zip(ingredients, quantities):
recipe.ingredients.append(Ingredient(name=ingredient, quantity=quantity))
for step, description in zip(steps, step_descriptions):
recipe.instructions.append(Instruction(step=step, description=description))
db.session.add(recipe)
db.session.commit()
flash('Recipe created successfully!', 'success')
return redirect(url_for('index'))
return render_template('new_recipe.html')
@bp.route('/account')
@login_required
def account():
return render_template('account.html')
@bp.route('/settings')
@login_required
def settings():
return render_template('settings.html')
@bp.route('/reset-password')
def resetpassword():
return render_template('reset-password.html')
@bp.route('/404')
def cuatrocerocuatro():
return render_template('404.html')
@bp.route('/charts')
@login_required
def charts():
return render_template('charts.html')
@bp.route('/help')
def help():
return render_template('help.html')
@bp.route('/uploads/<filename>')
def uploaded_file(filename):
return send_from_directory(current_app.config['UPLOAD_FOLDER'], filename)
@bp.route('/notifications')
def notifications():
return render_template('notifications.html')
@bp.route('/docs')
def docs():
return render_template('docs.html')
@bp.route('/orders')
def orders():
return render_template('orders.html')