|
|
|
@ -4,7 +4,7 @@ from flask_login import login_user, logout_user, login_required, current_user |
|
|
|
|
|
|
|
import os |
|
|
|
|
|
|
|
from .models import db, receta, Ingredient, Instruction |
|
|
|
from .models import db, Recipe, Ingredient, Instruction |
|
|
|
|
|
|
|
bp = Blueprint("paginas", __name__) |
|
|
|
|
|
|
|
@ -15,7 +15,7 @@ def index(): |
|
|
|
|
|
|
|
@bp.route('/recetas') |
|
|
|
def recetas(): |
|
|
|
recetas = receta.query.all() |
|
|
|
recetas = Recipe.query.all() |
|
|
|
return render_template('recetas.html', recetas=recetas) |
|
|
|
|
|
|
|
@bp.route('/404') |
|
|
|
@ -33,7 +33,7 @@ def account(): |
|
|
|
|
|
|
|
@bp.route('/receta/<int:receta_id>') |
|
|
|
def receta(receta_id): |
|
|
|
receta = receta.query.get_or_404(receta_id) |
|
|
|
receta = Recipe.query.get_or_404(receta_id) |
|
|
|
return render_template('recetas.html', receta=receta) |
|
|
|
|
|
|
|
@bp.route('/anade_receta', methods=['GET', 'POST']) |
|
|
|
@ -49,12 +49,12 @@ def anade_receta(): |
|
|
|
receta = receta(title=title, description=description, author=current_user) |
|
|
|
|
|
|
|
for i, (ingredient, quantity) in enumerate(zip(ingredients, quantities), start=1): |
|
|
|
receta.ingredients.append(Ingredient(name=ingredient, quantity=quantity, order=i)) |
|
|
|
Recipe.ingredients.append(Ingredient(name=ingredient, quantity=quantity, order=i)) |
|
|
|
|
|
|
|
for i, description in enumerate(step_descriptions, start=1): |
|
|
|
receta.instructions.append(Instruction(step=i, description=description, order=i)) |
|
|
|
Recipe.instructions.append(Instruction(step=i, description=description, order=i)) |
|
|
|
|
|
|
|
db.session.add(receta) |
|
|
|
db.session.add(Recipe) |
|
|
|
db.session.commit() |
|
|
|
flash('receta created successfully!', 'success') |
|
|
|
|
|
|
|
@ -63,46 +63,6 @@ def anade_receta(): |
|
|
|
|
|
|
|
return render_template('nueva_receta.html') |
|
|
|
|
|
|
|
@bp.route('/add_album', methods=['GET', 'POST']) |
|
|
|
@login_required |
|
|
|
def add_album(): |
|
|
|
if request.method == 'POST': |
|
|
|
|
|
|
|
name = request.form['name'] |
|
|
|
artist = request.form['artist'] |
|
|
|
year = request.form['year'] |
|
|
|
|
|
|
|
# Verificar que el campo 'cover_image' está en request.files |
|
|
|
if 'coverimage' not in request.files: |
|
|
|
return "No file part in the request", 400 |
|
|
|
|
|
|
|
cover_image = request.files['coverimage'] |
|
|
|
|
|
|
|
# Verificar que se ha seleccionado un archivo |
|
|
|
|
|
|
|
if cover_image.filename == '': |
|
|
|
return "No selected file", 400 |
|
|
|
|
|
|
|
if cover_image: |
|
|
|
image_filename = secure_filename(cover_image.filename) |
|
|
|
cover_image.save(os.path.join(current_app.config['UPLOAD_FOLDER'], image_filename)) |
|
|
|
else: |
|
|
|
image_filename = None |
|
|
|
|
|
|
|
new_album = Album(name=name, artist=artist, year=year, cover_image=image_filename) |
|
|
|
db.session.add(new_album) |
|
|
|
db.session.commit() |
|
|
|
|
|
|
|
return redirect(url_for('paginas.index')) |
|
|
|
|
|
|
|
return render_template('add_album.html') |
|
|
|
|
|
|
|
@bp.route('/album/<int:album_id>') |
|
|
|
def album(album_id): |
|
|
|
album = Album.query.get_or_404(album_id) |
|
|
|
songs = Song.query.filter_by(album_id=album_id).all() |
|
|
|
return render_template('album.html', album=album, songs=songs) |
|
|
|
|
|
|
|
@bp.route('/uploads/<filename>') |
|
|
|
def uploaded_file(filename): |
|
|
|
return send_from_directory(current_app.config['UPLOAD_FOLDER'], filename) |
|
|
|
@ -111,17 +71,7 @@ def uploaded_file(filename): |
|
|
|
def buscareceta(): |
|
|
|
query = request.args.get('query', '') |
|
|
|
if query: |
|
|
|
songs = Song.query.filter(Song.title.contains(query)).all() |
|
|
|
songs = Recipe.query.filter(Recipe.title.contains(query)).all() |
|
|
|
else: |
|
|
|
songs = [] |
|
|
|
return render_template('buscareceta.html', query=query, songs=songs) |
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/searchalbum') |
|
|
|
def searchalbum(): |
|
|
|
query = request.args.get('query', '') |
|
|
|
if query: |
|
|
|
albumes = Album.query.filter(Album.name.contains(query)).all() |
|
|
|
else: |
|
|
|
albumes = [] |
|
|
|
return render_template('searchalbum.html', query=query, albumes=albumes) |