Expand any dynamic values to their correct types / values.
(self, name, value)
| 491 | return cls._from_son(json_util.loads(json_data, **kwargs), created=created) |
| 492 | |
| 493 | def __expand_dynamic_values(self, name, value): |
| 494 | """Expand any dynamic values to their correct types / values.""" |
| 495 | if not isinstance(value, (dict, list, tuple)): |
| 496 | return value |
| 497 | |
| 498 | # If the value is a dict with '_cls' in it, turn it into a document |
| 499 | is_dict = isinstance(value, dict) |
| 500 | if is_dict and "_cls" in value: |
| 501 | cls = get_document(value["_cls"]) |
| 502 | return cls(**value) |
| 503 | |
| 504 | if is_dict: |
| 505 | value = {k: self.__expand_dynamic_values(k, v) for k, v in value.items()} |
| 506 | else: |
| 507 | value = [self.__expand_dynamic_values(name, v) for v in value] |
| 508 | |
| 509 | # Convert lists / values so we can watch for any changes on them |
| 510 | EmbeddedDocumentListField = _import_class("EmbeddedDocumentListField") |
| 511 | if isinstance(value, (list, tuple)) and not isinstance(value, BaseList): |
| 512 | if issubclass(type(self), EmbeddedDocumentListField): |
| 513 | value = EmbeddedDocumentList(value, self, name) |
| 514 | else: |
| 515 | value = BaseList(value, self, name) |
| 516 | elif isinstance(value, dict) and not isinstance(value, BaseDict): |
| 517 | value = BaseDict(value, self, name) |
| 518 | |
| 519 | return value |
| 520 | |
| 521 | def _mark_as_changed(self, key): |
| 522 | """Mark a key as explicitly changed by the user.""" |
no test coverage detected