models: Simplify JSON decoder code

This commit is contained in:
Thomas Adamcik 2015-04-08 23:23:55 +02:00
parent fb0e4dc7a1
commit 2cb2750b39

View File

@ -313,13 +313,11 @@ def model_json_decoder(dct):
"""
if '__model__' in dct:
# TODO: move models to a global constant once we split this module
models = {c.__name__: c for c in ImmutableObject.__subclasses__()}
model_name = dct.pop('__model__')
if model_name in models:
kwargs = {}
for key, value in dct.items():
kwargs[key] = value
return models[model_name](**kwargs)
return models[model_name](**dct)
return dct