From 1788e7fc6c45d5b245cc80e92ffab3d6016d8a45 Mon Sep 17 00:00:00 2001 From: boke0 Date: Tue, 2 Mar 2021 19:51:06 +0900 Subject: [PATCH] [update] --- mitama/db/model.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/mitama/db/model.py b/mitama/db/model.py index a028fe7..86cdf95 100755 --- a/mitama/db/model.py +++ b/mitama/db/model.py @@ -30,11 +30,9 @@ def genUUID(): class Model: prefix = None _id = Column(String(64), default=UUID(), primary_key=True, nullable=False) - _event_handlers = { - "create": Event(), - "update": Event(), - "delete": Event() - } + create = Event() + update = Event() + delete = Event() @classmethod def attribute_names(cls): @@ -80,14 +78,14 @@ def create(self): self.query.session.add(self) self.query.session.commit() try: - self.on("create")(self) + self.on("create")() except Exception: pass def update(self): self.query.session.commit() try: - self.on("update")(self) + self.on("update")() except Exception: pass @@ -95,16 +93,16 @@ def delete(self): self.query.session.delete(self) self.query.session.commit() try: - self.on("delete")(self) + self.on("delete")() except Exception: pass def on(self, evt): - return self._event_handlers[evt] + return getattr(self, evt) @classmethod - def listen(self, evt): - self._event_handlers[evt] = Event() + def listen(cls, evt): + setattr(cls, evt, Event()) @classmethod def list(cls, cond=None):