Fixed the *_family manager methods to correctly return typeclasses subclassed at any depth.
This commit is contained in:
parent
b244d70e16
commit
554d1b9834
2 changed files with 13 additions and 5 deletions
|
|
@ -230,8 +230,7 @@ class ObjectDB(TypedObject):
|
||||||
# location getsetter
|
# location getsetter
|
||||||
def __location_get(self):
|
def __location_get(self):
|
||||||
"Get location"
|
"Get location"
|
||||||
loc = _GA(_GA(self, "dbobj"), "db_location")
|
return self.db_location
|
||||||
return _GA(loc, "typeclass") if loc else loc
|
|
||||||
|
|
||||||
def __location_set(self, location):
|
def __location_set(self, location):
|
||||||
"Set location, checking for loops and allowing dbref"
|
"Set location, checking for loops and allowing dbref"
|
||||||
|
|
|
||||||
|
|
@ -68,13 +68,22 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
|
||||||
"""
|
"""
|
||||||
return super(TypedObjectManager, self).all(**kwargs).filter(db_typeclass_path=self.model.path)
|
return super(TypedObjectManager, self).all(**kwargs).filter(db_typeclass_path=self.model.path)
|
||||||
|
|
||||||
|
def _get_subclasses(self, cls):
|
||||||
|
"""
|
||||||
|
Recursively get all subclasses to a class
|
||||||
|
"""
|
||||||
|
all_subclasses = cls.__subclasses__()
|
||||||
|
for subclass in all_subclasses:
|
||||||
|
all_subclasses.extend(self._get_subclasses(subclass))
|
||||||
|
return all_subclasses
|
||||||
|
|
||||||
def get_family(self, **kwargs):
|
def get_family(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
Variation of get that not only returns the current
|
Variation of get that not only returns the current
|
||||||
typeclass but also all subclasses of that typeclass.
|
typeclass but also all subclasses of that typeclass.
|
||||||
"""
|
"""
|
||||||
paths = [self.model.path] + ["%s.%s" % (cls.__module__, cls.__name__)
|
paths = [self.model.path] + ["%s.%s" % (cls.__module__, cls.__name__)
|
||||||
for cls in self.model.__subclasses__()]
|
for cls in self._get_subclasses(self.model)]
|
||||||
kwargs.update({"db_typeclass_path__in":paths})
|
kwargs.update({"db_typeclass_path__in":paths})
|
||||||
return super(TypedObjectManager, self).get(**kwargs)
|
return super(TypedObjectManager, self).get(**kwargs)
|
||||||
|
|
||||||
|
|
@ -85,7 +94,7 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
|
||||||
"""
|
"""
|
||||||
# query, including all subclasses
|
# query, including all subclasses
|
||||||
paths = [self.model.path] + ["%s.%s" % (cls.__module__, cls.__name__)
|
paths = [self.model.path] + ["%s.%s" % (cls.__module__, cls.__name__)
|
||||||
for cls in self.model.__subclasses__()]
|
for cls in self._get_subclasses(self.model)]
|
||||||
kwargs.update({"db_typeclass_path__in":paths})
|
kwargs.update({"db_typeclass_path__in":paths})
|
||||||
return super(TypedObjectManager, self).filter(**kwargs)
|
return super(TypedObjectManager, self).filter(**kwargs)
|
||||||
|
|
||||||
|
|
@ -95,7 +104,7 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
|
||||||
the typeclass.
|
the typeclass.
|
||||||
"""
|
"""
|
||||||
paths = [self.model.path] + ["%s.%s" % (cls.__module__, cls.__name__)
|
paths = [self.model.path] + ["%s.%s" % (cls.__module__, cls.__name__)
|
||||||
for cls in self.model.__subclasses__()]
|
for cls in self._get_subclasses(self.model)]
|
||||||
return super(TypedObjectManager, self).all(**kwargs).filter(db_typeclass_path__in=paths)
|
return super(TypedObjectManager, self).all(**kwargs).filter(db_typeclass_path__in=paths)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue