From f43588531504effe30c41958c0abc5bbf132fc65 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Wed, 28 Jul 2021 09:12:57 +0300 Subject: [PATCH] Page d'erreur pour ScoValueError --- README.md | 1 - app/__init__.py | 8 ++++++++ app/templates/sco_value_error.html | 18 ++++++++++++++++++ app/views/essais.py | 14 +++++++++++++- app/views/notes.py | 2 ++ 5 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 app/templates/sco_value_error.html diff --git a/README.md b/README.md index c318cef254..201f42c3d8 100644 --- a/README.md +++ b/README.md @@ -185,7 +185,6 @@ Principaux contenus: # TODO - - page d'erreur ScoValueError - redirection pour authentification - import/export Excel diff --git a/app/__init__.py b/app/__init__.py index bcb5c567ac..c270c4e567 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,6 +1,7 @@ # -*- coding: UTF-8 -* # pylint: disable=invalid-name +from app.scodoc.sco_exceptions import ScoValueError import os import sys @@ -11,6 +12,7 @@ from flask import request from flask import Flask from flask import current_app from flask import g +from flask import render_template from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate from flask_login import LoginManager @@ -41,6 +43,10 @@ cache = Cache( # XXX TODO: configuration file ) +def handle_sco_value_error(exc): + return render_template("sco_value_error.html", exc=exc), 404 + + def create_app(config_class=Config): print("create_app") app = Flask(__name__, static_url_path="/ScoDoc/static", static_folder="static") @@ -55,6 +61,8 @@ def create_app(config_class=Config): cache.init_app(app) sco_cache.CACHE = cache + app.register_error_handler(ScoValueError, handle_sco_value_error) + from app.auth import bp as auth_bp app.register_blueprint(auth_bp, url_prefix="/auth") diff --git a/app/templates/sco_value_error.html b/app/templates/sco_value_error.html new file mode 100644 index 0000000000..e751f1d8cf --- /dev/null +++ b/app/templates/sco_value_error.html @@ -0,0 +1,18 @@ +{% extends 'base.html' %} +{% import 'bootstrap/wtf.html' as wtf %} + +{% block app_content %} + +

Erreur !

+ +

{{ exc }}

+ +

+ {% if g.scodoc_dept %} + continuer + {% else %} + continuer + {% endif %} +

+ +{% endblock %} \ No newline at end of file diff --git a/app/views/essais.py b/app/views/essais.py index 4f4280fbe1..67e49da714 100644 --- a/app/views/essais.py +++ b/app/views/essais.py @@ -11,6 +11,7 @@ from flask import g from flask import current_app from flask import render_template from flask import request +from flask import url_for from app.decorators import ( scodoc7func, @@ -23,8 +24,8 @@ from app.auth.models import Permission from app.views import essais_bp as bp -# import sco_core deviendra: from app.scodoc import sco_cache +from app.scodoc import sco_exceptions context = ScoDoc7Context(globals()) @@ -93,3 +94,14 @@ def essrep(): def testcheckbox(): # args = request.args return render_template("essais/testcheckbox.html") + + +# Test exception +@bp.route("/test_exception_value_error", methods=["GET"]) +def test_exception_value_error(): + raise sco_exceptions.ScoValueError( + "hello", + dest_url=url_for( + "notes.formsemestre_status", scodoc_dept="RT", formsemestre_id="SEM38882" + ), + ) diff --git a/app/views/notes.py b/app/views/notes.py index 1036c7bc1b..90dc463b99 100644 --- a/app/views/notes.py +++ b/app/views/notes.py @@ -1600,11 +1600,13 @@ sco_publish( "/do_evaluation_set_missing", sco_saisie_notes.do_evaluation_set_missing, Permission.ScoEnsView, + methods=["GET", "POST"], ) sco_publish( "/evaluation_suppress_alln", sco_saisie_notes.evaluation_suppress_alln, Permission.ScoView, + methods=["GET", "POST"], )