From 1bedc10e6a83c41866addd9ea45b9786524aaae7 Mon Sep 17 00:00:00 2001 From: jgenero Date: Sun, 16 Oct 2022 11:57:27 +0200 Subject: [PATCH] import script + config from od2m app --- app/__init__.py | 21 ++++++++++++++ app/app.py | 11 ++------ app/cmd/__init__.py | 3 ++ app/modeles/__init__.py | 3 ++ app/routes.py | 50 ++++++++++++++++++++++------------ app/templates/container.html | 6 ++-- app/templates/corpora_all.html | 4 +-- app/templates/corpus.html | 2 +- app/templates/home.html | 4 +-- 9 files changed, 70 insertions(+), 34 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index e69de29..b30cfbc 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -0,0 +1,21 @@ +import typing as t + +import werkzeug +from flask import render_template + +from .app import app +from .cmd import db_cli +from .routes import main + +app.register_blueprint(main) +app.cli.add_command(db_cli) + + +@app.errorhandler(404) +def page_not_found(e: werkzeug.exceptions.HTTPException) -> t.Tuple[t.Text, int]: + return render_template("404.html", title="Page non trouvée"), 404 + + +@app.errorhandler(500) +def internal_server_error(e: werkzeug.exceptions.HTTPException) -> t.Tuple[t.Text, int]: + return render_template("500.html", title="Erreur interne du serveur"), 500 diff --git a/app/app.py b/app/app.py index 26a228f..c81ca5c 100644 --- a/app/app.py +++ b/app/app.py @@ -1,19 +1,15 @@ -#!/usr/bin/python -# -*- coding: UTF-8 -*- - import os - from flask import Flask from playhouse.sqlite_ext import SqliteExtDatabase - from .debugger import initialize_flask_server_debugger_if_needed APPPATH = os.path.dirname(os.path.abspath(__file__)) templates = os.path.join(APPPATH, "templates") statics = os.path.join(APPPATH, "static") + app = Flask( "Application", template_folder=templates, @@ -21,11 +17,8 @@ app = Flask( ) # DB configuration -app.config["DATABASE"] = os.path.join(APPPATH, ".", "actes_princiers.db") +app.config["DATABASE"] = os.path.join(APPPATH, "..", "actes_princiers.sqlite") db = SqliteExtDatabase(app.config["DATABASE"], pragmas=[("journal_mode", "wal")]) # Enables debugging in VS Code if DEBUG env var is set _debugging = initialize_flask_server_debugger_if_needed() - -# Import de la route principale depuis le fichier routes.py -from .routes import home diff --git a/app/cmd/__init__.py b/app/cmd/__init__.py index e69de29..9f5f418 100644 --- a/app/cmd/__init__.py +++ b/app/cmd/__init__.py @@ -0,0 +1,3 @@ +from .db import db_cli + +__all__ = ["db_cli"] diff --git a/app/modeles/__init__.py b/app/modeles/__init__.py index e69de29..81bbefa 100644 --- a/app/modeles/__init__.py +++ b/app/modeles/__init__.py @@ -0,0 +1,3 @@ +from .data import Institution, State, Production_place, Diplo_type, Document, Acte, Individual, Duke, Produced_by + +__all__ = ["Institution", "State", "Production_place", "Diplo_type", "Document", "Acte", "Individual", "Duke", "Produced_by"] diff --git a/app/routes.py b/app/routes.py index bba3532..bdbe2d9 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,42 +1,58 @@ -#!/usr/bin/python -# -*- coding: UTF-8 -*- +import os +import re +import typing as t +import peewee +from flask import Blueprint, abort, render_template, request, send_from_directory +from playhouse.flask_utils import PaginatedQuery -""" - author : Jean-Damien Généro - date : 2022-10-01 - update : -""" +from .app import APPPATH +from .modeles import Institution, State, Production_place, Diplo_type, Document, Acte, Individual, Duke, Produced_by +RESULT_PAR_PAGES = 5 -# import des librairie -from flask import Flask, render_template, request -from .app import app +main = Blueprint("main", __name__, url_prefix="/") -@app.route("/") +@main.route("/") def home(): - """home route""" - return render_template("home.html") + """home route""" + return render_template("home.html") -@app.route("/about/") +@main.route("/about/") def about(): """home route""" return render_template("about.html") -@app.route("/actes/") +@main.route("/actes/") def corpora_all(): """copora all route""" return render_template("corpora_all.html") -@app.route("/actes/") # dont put a slash at the end +@main.route("/actes/") # dont put a slash at the end def actes(house): """actes route""" return render_template("corpus.html", house=house) -@app.route("/actes//") # dont put a slash at the end +@main.route("/actes//") # dont put a slash at the end def prince_corpus(house=None, prince=None): """copora prince route""" return render_template("prince_corpus.html", house=house, prince=prince) +@main.route("/contact") +def contact() -> t.Text: + """Displays the Contact page""" + return render_template("contact.html", title="Contact") + + +@main.route("/termsofservice") +def terms() -> t.Text: + """Displaysthe T&C page.""" + return render_template("terms.html", title="Mentions légales") + + +@main.route("/privacy") +def privacy() -> t.Text: + """Displays the privacy policy page.""" + return render_template("privacy.html", title="Politique de confidentialité") diff --git a/app/templates/container.html b/app/templates/container.html index 6033243..571e9bd 100644 --- a/app/templates/container.html +++ b/app/templates/container.html @@ -15,7 +15,7 @@