Set parent object

This commit is contained in:
Alex Root Junior 2017-05-30 21:42:12 +03:00
parent 1c81842167
commit e2dca9da0d
2 changed files with 14 additions and 1 deletions

View file

@ -35,8 +35,9 @@ class AIOGramBot:
if self.session and not self.session.closed: if self.session and not self.session.closed:
self.session.close() self.session.close()
def prepare_object(self, obj): def prepare_object(self, obj, parent=None):
obj.bot = self obj.bot = self
obj.parent = parent
return obj return obj
@property @property

View file

@ -55,6 +55,18 @@ class Deserializable:
if hasattr(attr, 'de_json'): if hasattr(attr, 'de_json'):
attr.bot = bot attr.bot = bot
@property
def parent(self):
return getattr(self, '_parent', None)
@parent.setter
def parent(self, value):
setattr(self, '_parent', value)
for name, attr in self.__dict__.items():
if hasattr(attr, 'de_json'):
attr.parent = self
@classmethod @classmethod
def de_json(cls, raw_data): def de_json(cls, raw_data):
""" """