add custom json encoder
This commit is contained in:
parent
4d424923f7
commit
c55fc07463
@ -1,7 +1,23 @@
|
|||||||
from flask import Blueprint
|
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 = Blueprint("api", __name__)
|
||||||
|
api.json_encoder = CustomJsonEncoder
|
||||||
from .errors import *
|
from .errors import *
|
||||||
from .appointement import *
|
from .appointement import *
|
||||||
from .planning import *
|
from .planning import *
|
||||||
|
Loading…
Reference in New Issue
Block a user