Fix merge conflict
This commit is contained in:
commit
788de8af47
3 changed files with 56 additions and 3 deletions
|
|
@ -538,13 +538,14 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
|
||||||
|
|
||||||
def typeclass_search(self, typeclass, include_children=False, include_parents=False):
|
def typeclass_search(self, typeclass, include_children=False, include_parents=False):
|
||||||
"""
|
"""
|
||||||
Searches through all objects returning those which has a certain typeclass.
|
Searches through all objects returning those which are of the
|
||||||
|
specified typeclass.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
typeclass (str or class): A typeclass class or a python path to a typeclass.
|
typeclass (str or class): A typeclass class or a python path to a typeclass.
|
||||||
include_children (bool, optional): Return objects with
|
include_children (bool, optional): Return objects with
|
||||||
given typeclass *and* all children inheriting from this
|
given typeclass *and* all children inheriting from this
|
||||||
typeclass. Mutuall exclusive to `include_parents`.
|
typeclass. Mutually exclusive to `include_parents`.
|
||||||
include_parents (bool, optional): Return objects with
|
include_parents (bool, optional): Return objects with
|
||||||
given typeclass *and* all parents to this typeclass.
|
given typeclass *and* all parents to this typeclass.
|
||||||
Mutually exclusive to `include_children`.
|
Mutually exclusive to `include_children`.
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ __all__ = (
|
||||||
"search_script_tag",
|
"search_script_tag",
|
||||||
"search_account_tag",
|
"search_account_tag",
|
||||||
"search_channel_tag",
|
"search_channel_tag",
|
||||||
|
"search_typeclass",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -362,3 +363,35 @@ def search_channel_tag(key=None, category=None, tagtype=None, **kwargs):
|
||||||
|
|
||||||
# search for tag objects (not the objects they are attached to
|
# search for tag objects (not the objects they are attached to
|
||||||
search_tag_object = ObjectDB.objects.get_tag
|
search_tag_object = ObjectDB.objects.get_tag
|
||||||
|
|
||||||
|
|
||||||
|
# Locate Objects by Typeclass
|
||||||
|
|
||||||
|
# search_objects_by_typeclass(typeclass="", include_children=False, include_parents=False) (also search_typeclass works)
|
||||||
|
# This returns the objects of the given typeclass
|
||||||
|
|
||||||
|
|
||||||
|
def search_objects_by_typeclass(typeclass, include_children=False, include_parents=False):
|
||||||
|
"""
|
||||||
|
Searches through all objects returning those of a certain typeclass.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
typeclass (str or class): A typeclass class or a python path to a typeclass.
|
||||||
|
include_children (bool, optional): Return objects with
|
||||||
|
given typeclass *and* all children inheriting from this
|
||||||
|
typeclass. Mutuall exclusive to `include_parents`.
|
||||||
|
include_parents (bool, optional): Return objects with
|
||||||
|
given typeclass *and* all parents to this typeclass.
|
||||||
|
Mutually exclusive to `include_children`.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
objects (list): The objects found with the given typeclasses.
|
||||||
|
"""
|
||||||
|
return ObjectDB.objects.typeclass_search(
|
||||||
|
typeclass=typeclass,
|
||||||
|
include_children=include_children,
|
||||||
|
include_parents=include_parents,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
search_typeclass = search_objects_by_typeclass
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,13 @@
|
||||||
from evennia.scripts.scripts import DefaultScript
|
from evennia.scripts.scripts import DefaultScript
|
||||||
from evennia.utils.test_resources import EvenniaTest
|
from evennia.utils.test_resources import EvenniaTest
|
||||||
from evennia.utils.search import search_script_attribute, search_script_tag, search_script
|
from evennia import DefaultObject, DefaultRoom
|
||||||
|
from evennia.objects.models import ObjectDB
|
||||||
|
from evennia.utils.search import (
|
||||||
|
search_script_attribute,
|
||||||
|
search_script_tag,
|
||||||
|
search_script,
|
||||||
|
search_typeclass,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestSearch(EvenniaTest):
|
class TestSearch(EvenniaTest):
|
||||||
|
|
@ -61,3 +68,15 @@ class TestSearch(EvenniaTest):
|
||||||
script, errors = DefaultScript.create("a-script")
|
script, errors = DefaultScript.create("a-script")
|
||||||
found = search_script("wrong_key")
|
found = search_script("wrong_key")
|
||||||
self.assertEqual(len(found), 0, errors)
|
self.assertEqual(len(found), 0, errors)
|
||||||
|
|
||||||
|
def test_search_typeclass(self):
|
||||||
|
"""Check that an object can be found by typeclass"""
|
||||||
|
obj = DefaultObject.create("test_obj")
|
||||||
|
found = search_typeclass("evennia.objects.objects.DefaultObject")
|
||||||
|
self.assertEqual(len(found), 1)
|
||||||
|
|
||||||
|
def test_search_wrong_typeclass(self):
|
||||||
|
"""Check that an object cannot be found by wrong typeclass"""
|
||||||
|
obj = DefaultObject.create("test_obj_2")
|
||||||
|
found = search_typeclass("not.a.typeclass")
|
||||||
|
self.assertEqual(len(found), 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue