Cleaned up the contents indexer.

This commit is contained in:
Andrew Bastien 2020-04-11 13:34:28 -07:00
parent 2d8b93a5b1
commit 467fd93f12
2 changed files with 19 additions and 12 deletions

View file

@ -53,7 +53,7 @@ class ContentsHandler(object):
Re-initialize the content cache Re-initialize the content cache
""" """
objects = [obj for obj in ObjectDB.objects.filter(db_location=self.obj) if obj.pk] objects = ObjectDB.objects.filter(db_location=self.obj)
self._pkcache = {obj.pk for obj in objects} self._pkcache = {obj.pk for obj in objects}
for obj in objects: for obj in objects:
for ctype in obj._content_types: for ctype in obj._content_types:

View file

@ -203,8 +203,8 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
without `obj.save()` having to be called explicitly. without `obj.save()` having to be called explicitly.
""" """
# Used for sorting / filtering. # Used for sorting / filtering in inventories / room contents.
_content_types = ("object") _content_types = ("object",)
# lockstring of newly created objects, for easy overloading. # lockstring of newly created objects, for easy overloading.
# Will be formatted with the appropriate attributes. # Will be formatted with the appropriate attributes.
@ -259,7 +259,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
and not self.db_account.attributes.get("_quell") and not self.db_account.attributes.get("_quell")
) )
def contents_get(self, exclude=None, category=None): def contents_get(self, exclude=None, content_type=None):
""" """
Returns the contents of this object, i.e. all Returns the contents of this object, i.e. all
objects that has this object set as its location. objects that has this object set as its location.
@ -268,13 +268,15 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
Args: Args:
exclude (Object): Object to exclude from returned exclude (Object): Object to exclude from returned
contents list contents list
category (str): A category to filter by. None for no filtering. content_type (str): A content_type to filter by. None for no
filtering.
Returns: Returns:
contents (list): List of contents of this Object. contents (list): List of contents of this Object.
Notes: Notes:
Also available as the `contents` property. Also available as the `contents` property, minus exclusion
and filtering.
""" """
con = self.contents_cache.get(exclude=exclude) con = self.contents_cache.get(exclude=exclude)
@ -1667,9 +1669,9 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
return "" return ""
# get and identify all objects # get and identify all objects
exits_list = filter_visible(self.contents_get(category='exit')) exits_list = filter_visible(self.contents_get(content_type='exit'))
users_list = filter_visible(self.contents_get(category='character')) users_list = filter_visible(self.contents_get(content_type='character'))
things_list = filter_visible(self.contents_get(category="object")) things_list = filter_visible(self.contents_get(content_type="object"))
things = defaultdict(list) things = defaultdict(list)
@ -2034,7 +2036,9 @@ class DefaultCharacter(DefaultObject):
a character avatar controlled by an account. a character avatar controlled by an account.
""" """
_content_types = ("character") # Tuple of types used for indexing inventory contents. Characters generally wouldn't be in
# anyone's inventory, but this also governs displays in room contents.
_content_types = ("character",)
# lockstring of newly created rooms, for easy overloading. # lockstring of newly created rooms, for easy overloading.
# Will be formatted with the appropriate attributes. # Will be formatted with the appropriate attributes.
lockstring = "puppet:id({character_id}) or pid({account_id}) or perm(Developer) or pperm(Developer);delete:id({account_id}) or perm(Admin)" lockstring = "puppet:id({character_id}) or pid({account_id}) or perm(Developer) or pperm(Developer);delete:id({account_id}) or perm(Admin)"
@ -2285,7 +2289,10 @@ class DefaultRoom(DefaultObject):
This is the base room object. It's just like any Object except its This is the base room object. It's just like any Object except its
location is always `None`. location is always `None`.
""" """
_content_types = ("room", "object") # A tuple of strings used for indexing this object inside an inventory.
# Generally, a room isn't expected to HAVE a location, but maybe in some games?
_content_types = ("room",)
# lockstring of newly created rooms, for easy overloading. # lockstring of newly created rooms, for easy overloading.
# Will be formatted with the {id} of the creating object. # Will be formatted with the {id} of the creating object.
lockstring = ( lockstring = (
@ -2435,7 +2442,7 @@ class DefaultExit(DefaultObject):
exits simply by giving the exit-object's name on its own. exits simply by giving the exit-object's name on its own.
""" """
_content_types = ("exit") _content_types = ("exit",)
exit_command = ExitCommand exit_command = ExitCommand
priority = 101 priority = 101