s/Entity.to_json/Entity.to_dict/g

stuff
This commit is contained in:
Fabio Manganiello 2023-03-06 23:44:50 +01:00
parent b9efa9fa30
commit 1781a19a79
Signed by: blacklight
GPG key ID: D90FBA7F76362774
2 changed files with 4 additions and 6 deletions

View file

@ -94,7 +94,7 @@ if 'entity' not in Base.metadata:
'polymorphic_on': type, 'polymorphic_on': type,
} }
@classmethod @classmethod # type: ignore
@property @property
def columns(cls) -> Tuple[ColumnProperty]: def columns(cls) -> Tuple[ColumnProperty]:
inspector = schema_inspect(cls) inspector = schema_inspect(cls)
@ -106,8 +106,6 @@ if 'entity' not in Base.metadata:
This method returns the "external" key of an entity. This method returns the "external" key of an entity.
""" """
return (str(self.external_id or self.id), str(self.plugin)) return (str(self.external_id or self.id), str(self.plugin))
return (str(self.external_id), str(self.plugin))
return (str(self.external_id or self.id), str(self.plugin))
def _serialize_value(self, col: ColumnProperty) -> Any: def _serialize_value(self, col: ColumnProperty) -> Any:
val = getattr(self, col.key) val = getattr(self, col.key)
@ -117,14 +115,14 @@ if 'entity' not in Base.metadata:
return val return val
def to_json(self) -> dict: def to_dict(self) -> dict:
return {col.key: self._serialize_value(col) for col in self.columns} return {col.key: self._serialize_value(col) for col in self.columns}
def __repr__(self): def __repr__(self):
return str(self) return str(self)
def __str__(self): def __str__(self):
return json.dumps(self.to_json()) return json.dumps(self.to_dict())
def __setattr__(self, key, value): def __setattr__(self, key, value):
matching_columns = [c for c in self.columns if c.expression.name == key] matching_columns = [c for c in self.columns if c.expression.name == key]

View file

@ -7,7 +7,7 @@ from platypush.message.event import Event
class EntityEvent(Event): class EntityEvent(Event):
def __init__(self, entity: Union[Entity, dict], *args, **kwargs): def __init__(self, entity: Union[Entity, dict], *args, **kwargs):
if isinstance(entity, Entity): if isinstance(entity, Entity):
entity = entity.to_json() entity = entity.to_dict()
super().__init__(entity=entity, *args, **kwargs) super().__init__(entity=entity, *args, **kwargs)