[fix] Display the date in a correct format

This commit is contained in:
ljf 2018-06-05 17:57:06 +02:00
parent cee5eb562a
commit 4e4fb4125b

View file

@ -1,5 +1,6 @@
import logging import logging
from json.encoder import JSONEncoder from json.encoder import JSONEncoder
import datetime
logger = logging.getLogger('moulinette.utils.serialize') logger = logging.getLogger('moulinette.utils.serialize')
@ -24,6 +25,10 @@ class JSONExtendedEncoder(JSONEncoder):
hasattr(o, '__iter__') and hasattr(o, 'next')): hasattr(o, '__iter__') and hasattr(o, 'next')):
return list(o) return list(o)
# Convert compatible containers into list
if isinstance(o, datetime.datetime) or isinstance(o, datetime.date):
return str(o)
# Return the repr for object that json can't encode # Return the repr for object that json can't encode
logger.warning('cannot properly encode in JSON the object %s, ' logger.warning('cannot properly encode in JSON the object %s, '
'returned repr is: %r', type(o), o) 'returned repr is: %r', type(o), o)