mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
[enh] teach YunoHost how to serialize Table objects
This commit is contained in:
parent
c44191bc2c
commit
ae93f8044e
2 changed files with 5 additions and 4 deletions
|
@ -512,10 +512,6 @@ class Interface(BaseInterface):
|
|||
import json
|
||||
from moulinette.utils.serialize import JSONExtendedEncoder
|
||||
|
||||
# retro compat situation
|
||||
if isinstance(ret, Table):
|
||||
ret = ret.data
|
||||
|
||||
print(json.dumps(ret, cls=JSONExtendedEncoder))
|
||||
else:
|
||||
plain_print_dict(ret)
|
||||
|
|
|
@ -2,6 +2,8 @@ import logging
|
|||
from json.encoder import JSONEncoder
|
||||
import datetime
|
||||
|
||||
from moulinette import Table
|
||||
|
||||
logger = logging.getLogger("moulinette.utils.serialize")
|
||||
|
||||
|
||||
|
@ -36,6 +38,9 @@ class JSONExtendedEncoder(JSONEncoder):
|
|||
o = o.replace(tzinfo=pytz.utc)
|
||||
return o.isoformat()
|
||||
|
||||
if isinstance(o, Table):
|
||||
return o.data
|
||||
|
||||
# Return the repr for object that json can't encode
|
||||
logger.warning(
|
||||
"cannot properly encode in JSON the object %s, " "returned repr is: %r",
|
||||
|
|
Loading…
Add table
Reference in a new issue