diff options
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r-- | ishtar_common/utils.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index 95a7ebbaa..e69ef0290 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -112,10 +112,31 @@ class InlineClass: """ Dynamic class used in templates """ + def __init__(self, dct): for k in dct: setattr(self, k, dct[k]) + def toJSON(self): + return json.dumps( + self, + default=lambda o: o.__dict__, + sort_keys=True, + indent=4 + ) + + +def json_used_equipments(value): + res = [] + for gp in value: + res.append(gp[:4] + [cost.toJSON() for cost in gp[-1]]) + return res + + +JSON_SERIALIZATION = { + "used_equipments": json_used_equipments +} + def fake_task(*args): def fake(func): |