Turns out normal filter manager methods should also accept *args. Resolves #793.
This commit is contained in:
parent
a1eadef686
commit
ce26ee0a25
2 changed files with 20 additions and 17 deletions
|
|
@ -3,7 +3,7 @@ Evennia menu system.
|
||||||
|
|
||||||
Contribution - Griatch 2011
|
Contribution - Griatch 2011
|
||||||
|
|
||||||
> Note that the evennia/utils/menu.py module is probably a better and
|
> Note that the evennia/utils/evmenu.py module is probably a better and
|
||||||
more flexible implementation of a menu system than this. Try that
|
more flexible implementation of a menu system than this. Try that
|
||||||
first.
|
first.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -526,37 +526,40 @@ class TypeclassManager(TypedObjectManager):
|
||||||
kwargs.update({"db_typeclass_path":self.model.path})
|
kwargs.update({"db_typeclass_path":self.model.path})
|
||||||
return super(TypedObjectManager, self).get(**kwargs)
|
return super(TypedObjectManager, self).get(**kwargs)
|
||||||
|
|
||||||
def filter(self, **kwargs):
|
def filter(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Overload of the standard filter function. This filter will
|
Overload of the standard filter function. This filter will
|
||||||
limit itself to only the current typeclass.
|
limit itself to only the current typeclass.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
args (any): These are passed on as arguments to the default
|
||||||
|
django filter method.
|
||||||
Kwargs:
|
Kwargs:
|
||||||
kwargs (any): These are passed on as normal arguments
|
kwargs (any): These are passed on as normal arguments
|
||||||
to the default django filter method.
|
to the default django filter method.
|
||||||
Returns:
|
Returns:
|
||||||
objects (list): The objects found.
|
objects (queryset): The objects found.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
kwargs.update({"db_typeclass_path":self.model.path})
|
kwargs.update({"db_typeclass_path":self.model.path})
|
||||||
return super(TypedObjectManager, self).filter(**kwargs)
|
return super(TypedObjectManager, self).filter(*args, **kwargs)
|
||||||
|
|
||||||
def all(self, **kwargs):
|
def all(self):
|
||||||
"""
|
"""
|
||||||
Overload method to return all matches, filtering for typeclass.
|
Overload method to return all matches, filtering for typeclass.
|
||||||
|
|
||||||
Kwargs:
|
|
||||||
kwargs (any): These are passed on as normal arguments
|
|
||||||
to the default django all method (usually none are given).
|
|
||||||
Returns:
|
Returns:
|
||||||
objects (list): The objects found.
|
objects (queryset): The objects found.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return super(TypedObjectManager, self).all(**kwargs).filter(db_typeclass_path=self.model.path)
|
return super(TypedObjectManager, self).all().filter(db_typeclass_path=self.model.path)
|
||||||
|
|
||||||
def _get_subclasses(self, cls):
|
def _get_subclasses(self, cls):
|
||||||
"""
|
"""
|
||||||
Recursively get all subclasses to a class.
|
Recursively get all subclasses to a class.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
cls (classoject): A class to get subclasses from.
|
||||||
"""
|
"""
|
||||||
all_subclasses = cls.__subclasses__()
|
all_subclasses = cls.__subclasses__()
|
||||||
for subclass in all_subclasses:
|
for subclass in all_subclasses:
|
||||||
|
|
@ -584,11 +587,14 @@ class TypeclassManager(TypedObjectManager):
|
||||||
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)
|
||||||
|
|
||||||
def filter_family(self, **kwargs):
|
def filter_family(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Variation of filter that allows results both from typeclass
|
Variation of filter that allows results both from typeclass
|
||||||
and from subclasses of typeclass
|
and from subclasses of typeclass
|
||||||
|
|
||||||
|
Args:
|
||||||
|
args (any): These are passed on as arguments to the default
|
||||||
|
django filter method.
|
||||||
Kwargs:
|
Kwargs:
|
||||||
kwargs (any): These are passed on as normal arguments
|
kwargs (any): These are passed on as normal arguments
|
||||||
to the default django filter method.
|
to the default django filter method.
|
||||||
|
|
@ -600,22 +606,19 @@ class TypeclassManager(TypedObjectManager):
|
||||||
paths = [self.model.path] + ["%s.%s" % (cls.__module__, cls.__name__)
|
paths = [self.model.path] + ["%s.%s" % (cls.__module__, cls.__name__)
|
||||||
for cls in self._get_subclasses(self.model)]
|
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(*args, **kwargs)
|
||||||
|
|
||||||
def all_family(self, **kwargs):
|
def all_family(self):
|
||||||
"""
|
"""
|
||||||
Return all matches, allowing matches from all subclasses of
|
Return all matches, allowing matches from all subclasses of
|
||||||
the typeclass.
|
the typeclass.
|
||||||
|
|
||||||
Kwargs:
|
|
||||||
kwargs (any): These are passed on as normal arguments
|
|
||||||
to the default django all method (usually none are given).
|
|
||||||
Returns:
|
Returns:
|
||||||
objects (list): The objects found.
|
objects (list): The objects found.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
paths = [self.model.path] + ["%s.%s" % (cls.__module__, cls.__name__)
|
paths = [self.model.path] + ["%s.%s" % (cls.__module__, cls.__name__)
|
||||||
for cls in self._get_subclasses(self.model)]
|
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().filter(db_typeclass_path__in=paths)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue