File size: 1,144 Bytes
46e055c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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/<int:matiere_id>')
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/<int:sous_categorie_id>')
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/<int:texte_id>')
def texte(texte_id):
    texte = Texte.query.get_or_404(texte_id)
    return render_template('texte.html', texte=texte)