|
@ -77,7 +77,7 @@ def register_transformer( |
|
|
if model_name not in _model_transformers: |
|
|
if model_name not in _model_transformers: |
|
|
_model_transformers[model_name] = model_serializer |
|
|
_model_transformers[model_name] = model_serializer |
|
|
else: |
|
|
else: |
|
|
raise ValueError( |
|
|
|
|
|
|
|
|
raise KeyError( |
|
|
' '.join([ |
|
|
' '.join([ |
|
|
'A transformer for type "{}" already exists with class "{}".', |
|
|
'A transformer for type "{}" already exists with class "{}".', |
|
|
'Cannot register a new transformer with class "{}"' |
|
|
'Cannot register a new transformer with class "{}"' |
|
@ -100,12 +100,12 @@ def serialize_model(model_obj: db.Model, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def deserialize_model( |
|
|
def deserialize_model( |
|
|
model_type: str, |
|
|
|
|
|
|
|
|
model_type: Type[db.Model], |
|
|
json_model_object: dict, |
|
|
json_model_object: dict, |
|
|
options: Optional[List[str]] = None) -> db.Model: |
|
|
options: Optional[List[str]] = None) -> db.Model: |
|
|
"""Lookup a Model and hand it off to the deserializer.""" |
|
|
"""Lookup a Model and hand it off to the deserializer.""" |
|
|
try: |
|
|
try: |
|
|
transformer = _model_transformers[model_type] |
|
|
|
|
|
|
|
|
transformer = _model_transformers[model_type.__name__] |
|
|
return transformer( |
|
|
return transformer( |
|
|
transformer.type()).deserialize(json_model_object, options) |
|
|
transformer.type()).deserialize(json_model_object, options) |
|
|
except KeyError: |
|
|
except KeyError: |
|
|