API change. Removed managers for Attributes and Tags - these are instead incoorporated into the TypedObjectManager which all Typeclassed object handlers inherit from. This concludes the refactor started in #529. This means that access to Attributes/Permissions/Aliases and Tags/nicks are done directly through e.g. ObjectDB.objects.get_by_tag() (or ev.managers.objects.get_by_tag) rather than using Tag.get_obj_with_tag and specifying the model type manually. The create_tag() method was also moved into the TypedObjectManager as part of removing the Tagmanager. As part of this change, Tag and Attribute was also removed from the ev interface.

This commit is contained in:
Griatch 2014-10-25 22:40:38 +02:00
parent 08b18524fd
commit 5b42b31240
6 changed files with 123 additions and 216 deletions

View file

@ -40,7 +40,6 @@ _PlayerDB = None
_to_object = None
_ChannelDB = None
_channelhandler = None
_Tag = None
# limit symbol import from API
@ -450,18 +449,6 @@ def create_channel(key, aliases=None, desc=None,
channel = create_channel
def create_tag(self, key=None, category=None, data=None):
"""
Create a tag. This makes sure to create case-insensitive tags.
Note that if the exact same tag configuration (key+category)
exists, it will be re-used. A data keyword will overwrite existing
data on a tag (it is not part of what makes the tag unique).
"""
global _Tag
if not _Tag:
from src.typeclasses.models import Tag as _Tag
return _Tag.objects.create_tag(key=key, category=category, data=data)
#
# Player creation methods

View file

@ -180,34 +180,48 @@ help_entry_search = search_help_entry
help_entries = search_help_entries
# Locate Attributes
# search_object_attribute(key, category, value, strvalue) (also search_attribute works)
# search_player_attribute(key, category, value, strvalue) (also search_attribute works)
# search_script_attribute(key, category, value, strvalue) (also search_attribute works)
# search_channel_attribute(key, category, value, strvalue) (also search_attribute works)
# Note that these return the object attached to the Attribute,
# not the attribute object itself (this is usually what you want)
def search_object_attribute(key=None, category=None, value=None, strvalue=None):
return ObjectDB.objects.get_by_attribute(key=key, category=category, value=value, strvalue=strvalue)
def search_player_attribute(key=None, category=None, value=None, strvalue=None):
return PlayerDB.objects.get_by_attribute(key=key, category=category, value=value, strvalue=strvalue)
def search_script_attribute(key=None, category=None, value=None, strvalue=None):
return ScriptDB.objects.get_by_attribute(key=key, category=category, value=value, strvalue=strvalue)
def search_channel_attribute(key=None, category=None, value=None, strvalue=None):
return Channel.objects.get_by_attribute(key=key, category=category, value=value, strvalue=strvalue)
# search for attribute objects
search_attribute_object = ObjectDB.objects.get_attribute
# Locate Tags
# search_object_tag(key, category=None) (also search_tag works)
# search_player_tag(key, category=None)
# search_script_tag(key, category=None)
# search_channel_tag(key, category=None)
# search_object_tag(key=None, category=None) (also search_tag works)
# search_player_tag(key=None, category=None)
# search_script_tag(key=None, category=None)
# search_channel_tag(key=None, category=None)
# Note that this returns the object attached to the tag, not the tag itself
# (this is usually what you want)
search_tag = Tag.objects.get_objs_with_tag
def search_object_tag(key, category=None): return Tag.objects.get_objs_with_tag(key, category, model="objects.objectdb")
def search_player_tag(key, category=None): return Tag.objects.get_objs_with_tag(key, category, model="players.playerdb")
def search_script_tag(key, category=None): return Tag.objects.get_objs_with_tag(key, category, model="scripts.scriptdb")
def search_channel_tag(key, category=None): return Tag.objects.get_objs_with_tag(key, category, model="comms.channeldb")
# Note that this returns the object attached to the tag, not the tag
# object itself (this is usually what you want)
def search_object_tag(key=None, category=None):
return ObjectDB.objects.get_by_tag(key=key, category=category)
search_tag = search_object_tag # this is the most common case
def search_player_tag(key=None, category=None):
return PlayerDB.objects.get_by_tag(key=key, category=category)
def search_script_tag(key=None, category=None):
return ScriptDB.objects.get_by_tag(key=key, category=category)
def search_channel_tag(key=None, category=None):
return Channel.objects.get_by_tag(key=key, category=category)
# """
# Search and return all tags matching any combination of
# the search criteria.
# search_key (string) - the tag identifier
# category (string) - the tag category
# model - one of
# "objects.objectdb" (default), "players.playerdb",
# "scripts.scriptdb" or "comms.channeldb"
#
# Returns a single Tag (or None) if both key and category is given,
# otherwise it will return a list.
# """
# This returns the tag object itself.
search_tag_object = Tag.objects.get_tag
# search for tag objects
search_tag_object = ObjectDB.objects.get_tag