from flask import Blueprint, render_template, abort from app.models import Matiere, SousCategorie, Texte from sqlalchemy import func bp = Blueprint('main', __name__) @bp.route('/') def index(): matieres = Matiere.query.order_by(func.lower(Matiere.nom)).all() return render_template('index.html', matieres=matieres) @bp.route('/matiere/') def matiere(matiere_id): matiere = Matiere.query.get_or_404(matiere_id) sous_categories = matiere.sous_categories.order_by(func.lower(SousCategorie.nom)).all() # Tri insensible return render_template('matiere.html', matiere=matiere, sous_categories=sous_categories) @bp.route('/sous_categorie/') def sous_categorie(sous_categorie_id): sous_categorie = SousCategorie.query.get_or_404(sous_categorie_id) textes = sous_categorie.textes.order_by(Texte.titre).all() # Tri par titre return render_template('sous_categorie.html', sous_categorie=sous_categorie, textes=textes) @bp.route('/texte/') def texte(texte_id): texte = Texte.query.get_or_404(texte_id) return render_template('texte.html', texte=texte)