1
0
forked from ScoDoc/ScoDoc

Page d'erreur pour ScoValueError

This commit is contained in:
Emmanuel Viennet 2021-07-28 09:12:57 +03:00
parent 18b802130a
commit f435885315
5 changed files with 41 additions and 2 deletions

View File

@ -185,7 +185,6 @@ Principaux contenus:
# TODO # TODO
- page d'erreur ScoValueError
- redirection pour authentification - redirection pour authentification
- import/export Excel - import/export Excel

View File

@ -1,6 +1,7 @@
# -*- coding: UTF-8 -* # -*- coding: UTF-8 -*
# pylint: disable=invalid-name # pylint: disable=invalid-name
from app.scodoc.sco_exceptions import ScoValueError
import os import os
import sys import sys
@ -11,6 +12,7 @@ from flask import request
from flask import Flask from flask import Flask
from flask import current_app from flask import current_app
from flask import g from flask import g
from flask import render_template
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate from flask_migrate import Migrate
from flask_login import LoginManager 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): def create_app(config_class=Config):
print("create_app") print("create_app")
app = Flask(__name__, static_url_path="/ScoDoc/static", static_folder="static") 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) cache.init_app(app)
sco_cache.CACHE = cache sco_cache.CACHE = cache
app.register_error_handler(ScoValueError, handle_sco_value_error)
from app.auth import bp as auth_bp from app.auth import bp as auth_bp
app.register_blueprint(auth_bp, url_prefix="/auth") app.register_blueprint(auth_bp, url_prefix="/auth")

View File

@ -0,0 +1,18 @@
{% extends 'base.html' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% block app_content %}
<h2>Erreur !</h2>
<p>{{ exc }}</p>
<p>
{% if g.scodoc_dept %}
<a href="{{ exc.dest_url or url_for('scolar.index_html', scodoc_dept=g.scodoc_dept) }}">continuer</a>
{% else %}
<a href="{{ exc.dest_url or url_for('scodoc.index') }}">continuer</a>
{% endif %}
</p>
{% endblock %}

View File

@ -11,6 +11,7 @@ from flask import g
from flask import current_app from flask import current_app
from flask import render_template from flask import render_template
from flask import request from flask import request
from flask import url_for
from app.decorators import ( from app.decorators import (
scodoc7func, scodoc7func,
@ -23,8 +24,8 @@ from app.auth.models import Permission
from app.views import essais_bp as bp from app.views import essais_bp as bp
# import sco_core deviendra:
from app.scodoc import sco_cache from app.scodoc import sco_cache
from app.scodoc import sco_exceptions
context = ScoDoc7Context(globals()) context = ScoDoc7Context(globals())
@ -93,3 +94,14 @@ def essrep():
def testcheckbox(): def testcheckbox():
# args = request.args # args = request.args
return render_template("essais/testcheckbox.html") 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"
),
)

View File

@ -1600,11 +1600,13 @@ sco_publish(
"/do_evaluation_set_missing", "/do_evaluation_set_missing",
sco_saisie_notes.do_evaluation_set_missing, sco_saisie_notes.do_evaluation_set_missing,
Permission.ScoEnsView, Permission.ScoEnsView,
methods=["GET", "POST"],
) )
sco_publish( sco_publish(
"/evaluation_suppress_alln", "/evaluation_suppress_alln",
sco_saisie_notes.evaluation_suppress_alln, sco_saisie_notes.evaluation_suppress_alln,
Permission.ScoView, Permission.ScoView,
methods=["GET", "POST"],
) )