diff --git a/ITPlanning/api/__init__.py b/ITPlanning/api/__init__.py index 6e5a747..55f692b 100644 --- a/ITPlanning/api/__init__.py +++ b/ITPlanning/api/__init__.py @@ -1,7 +1,23 @@ from flask import Blueprint +from flask.json import JSONEncoder +from datetime import datetime + + +class CustomJsonEncoder(JSONEncoder): + def default(self, obj): + try: + if isinstance(obj, datetime): + return obj.strftime("%Y-%m-%dT%H%M") + iterable = iter(obj) + except TypeError: + pass + else: + return list(iterable) + return JSONEncoder.default(self, obj) + api = Blueprint("api", __name__) - +api.json_encoder = CustomJsonEncoder from .errors import * from .appointement import * from .planning import *