diff --git a/app/__init__.py b/app/__init__.py index 54fd0a0e2e..aafade1232 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -16,6 +16,7 @@ from flask import current_app, g, request from flask import Flask from flask import abort, flash, has_request_context, jsonify from flask import render_template +from flask.json import JSONEncoder from flask.logging import default_handler from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate @@ -108,6 +109,15 @@ def handle_invalid_usage(error): return response +# JSON ENCODING +class ScoDocJSONEncoder(JSONEncoder): + def default(self, o): + if isinstance(o, datetime.datetime): + return o.isoformat() + + return super().default(o) + + def render_raw_html(template_filename: str, **args) -> str: """Load and render an HTML file _without_ using Flask Necessary for 503 error mesage, when DB is down and Flask may be broken. @@ -205,6 +215,7 @@ class ReverseProxied(object): def create_app(config_class=DevConfig): app = Flask(__name__, static_url_path="/ScoDoc/static", static_folder="static") app.wsgi_app = ReverseProxied(app.wsgi_app) + app.json_encoder = ScoDocJSONEncoder app.logger.setLevel(logging.INFO) # Evite de logguer toutes les requetes dans notre log