Refactor some names to make api cleaner to read.
This commit is contained in:
parent
f7936df104
commit
506c5c6d39
7 changed files with 91 additions and 12 deletions
|
|
@ -52,6 +52,7 @@ search_object = None
|
|||
search_script = None
|
||||
search_player = None
|
||||
search_channel = None
|
||||
search_message = None
|
||||
search_help = None
|
||||
search_tag = None
|
||||
|
||||
|
|
@ -73,6 +74,10 @@ ansi = None
|
|||
spawn = None
|
||||
managers = None
|
||||
contrib = None
|
||||
EvMenu = None
|
||||
EvTable = None
|
||||
EvForm = None
|
||||
EvEditor = None
|
||||
|
||||
# Handlers
|
||||
SESSION_HANDLER = None
|
||||
|
|
@ -150,6 +155,7 @@ def _init():
|
|||
from .utils.search import search_object
|
||||
from .utils.search import search_script
|
||||
from .utils.search import search_player
|
||||
from .utils.search import search_message
|
||||
from .utils.search import search_channel
|
||||
from .utils.search import search_help
|
||||
from .utils.search import search_tag
|
||||
|
|
@ -170,6 +176,10 @@ def _init():
|
|||
from .utils import ansi
|
||||
from .utils.spawner import spawn
|
||||
from . import contrib
|
||||
from .utils.evmenu import EvMenu
|
||||
from .utils.evtable import EvTable
|
||||
from .utils.evform import EvForm
|
||||
from .utils.eveditor import EvEditor
|
||||
|
||||
# handlers
|
||||
from .scripts.tickerhandler import TICKER_HANDLER
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ class MsgManager(TypedObjectManager):
|
|||
"""
|
||||
return self.filter(db_receivers_channels=channel).exclude(db_hide_from_channels=channel)
|
||||
|
||||
def message_search(self, sender=None, receiver=None, freetext=None, dbref=None):
|
||||
def search_message(self, sender=None, receiver=None, freetext=None, dbref=None):
|
||||
"""
|
||||
Search the message database for particular messages. At least
|
||||
one of the arguments must be given to do a search.
|
||||
|
|
@ -309,7 +309,8 @@ class MsgManager(TypedObjectManager):
|
|||
fulltext_restrict = Q()
|
||||
# execute the query
|
||||
return list(self.filter(sender_restrict & receiver_restrict & fulltext_restrict))
|
||||
|
||||
# back-compatibility alias
|
||||
message_search = search_message
|
||||
|
||||
#
|
||||
# Channel manager
|
||||
|
|
@ -383,7 +384,7 @@ class ChannelDBManager(TypedObjectManager):
|
|||
return []
|
||||
|
||||
@returns_typeclass_list
|
||||
def channel_search(self, ostring, exact=True):
|
||||
def search_channel(self, ostring, exact=True):
|
||||
"""
|
||||
Search the channel database for a particular channel.
|
||||
|
||||
|
|
@ -413,6 +414,8 @@ class ChannelDBManager(TypedObjectManager):
|
|||
if ostring.lower() in [a.lower
|
||||
for a in channel.aliases.all()]]
|
||||
return channels
|
||||
# back-compatibility alias
|
||||
channel_search = search_channel
|
||||
|
||||
class ChannelManager(ChannelDBManager, TypeclassManager):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -291,7 +291,7 @@ class ObjectDBManager(TypedObjectManager):
|
|||
# main search methods and helper functions
|
||||
|
||||
@returns_typeclass_list
|
||||
def object_search(self, searchdata,
|
||||
def search_object(self, searchdata,
|
||||
attribute_name=None,
|
||||
typeclass=None,
|
||||
candidates=None,
|
||||
|
|
@ -412,6 +412,8 @@ class ObjectDBManager(TypedObjectManager):
|
|||
pass
|
||||
# return a list (possibly empty)
|
||||
return matches
|
||||
# alias for backwards compatibility
|
||||
object_search = search_object
|
||||
|
||||
#
|
||||
# ObjectManager Copy method
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ class PlayerDBManager(TypedObjectManager, UserManager):
|
|||
return None
|
||||
|
||||
@returns_typeclass_list
|
||||
def player_search(self, ostring, exact=True, typeclass=None):
|
||||
def search_player(self, ostring, exact=True, typeclass=None):
|
||||
"""
|
||||
Searches for a particular player by name or
|
||||
database id.
|
||||
|
|
@ -182,7 +182,8 @@ class PlayerDBManager(TypedObjectManager, UserManager):
|
|||
return self.filter(**query)
|
||||
else:
|
||||
return self.filter(**query)
|
||||
|
||||
# back-compatibility alias
|
||||
player_search = search_player
|
||||
|
||||
class PlayerManager(PlayerDBManager, TypeclassManager):
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -217,7 +217,7 @@ class ScriptDBManager(TypedObjectManager):
|
|||
return nr_started, nr_stopped
|
||||
|
||||
@returns_typeclass_list
|
||||
def script_search(self, ostring, obj=None, only_timed=False):
|
||||
def search_script(self, ostring, obj=None, only_timed=False):
|
||||
"""
|
||||
Search for a particular script.
|
||||
|
||||
|
|
@ -245,6 +245,8 @@ class ScriptDBManager(TypedObjectManager):
|
|||
timed_restriction = only_timed and Q(interval__gt=0) or Q()
|
||||
scripts = self.filter(timed_restriction & obj_restriction & Q(db_key__iexact=ostring))
|
||||
return scripts
|
||||
# back-compatibility alias
|
||||
script_search = search_script
|
||||
|
||||
def copy_script(self, original_script, new_key=None, new_obj=None, new_locks=None):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -605,6 +605,8 @@ class EvEditor(object):
|
|||
def __init__(self, caller, loadfunc=None, savefunc=None,
|
||||
quitfunc=None, key="", persistent=False):
|
||||
"""
|
||||
Launches a full in-game line editor, mimicking the functionality of VIM.
|
||||
|
||||
Args:
|
||||
caller (Object): Who is using the editor.
|
||||
loadfunc (callable, optional): This will be called as
|
||||
|
|
|
|||
|
|
@ -218,17 +218,76 @@ search_attribute_object = ObjectDB.objects.get_attribute
|
|||
|
||||
# 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):
|
||||
def search_object_by_tag(key=None, category=None):
|
||||
"""
|
||||
Find object based on tag or category.
|
||||
|
||||
Args:
|
||||
key (str, optional): The tag key to search for.
|
||||
category (str, optional): The category of tag
|
||||
to search for. If not set, uncategorized
|
||||
tags will be searched.
|
||||
|
||||
Returns:
|
||||
matches (list): List of Objects with tags matching
|
||||
the search criteria, or an empty list if no
|
||||
matches were found.
|
||||
|
||||
"""
|
||||
return ObjectDB.objects.get_by_tag(key=key, category=category)
|
||||
search_tag = search_object_tag # this is the most common case
|
||||
search_tag = search_object_by_tag # this is the most common case
|
||||
search_object_by_tag = search_tag
|
||||
def search_player_tag(key=None, category=None):
|
||||
"""
|
||||
Find player based on tag or category.
|
||||
|
||||
Args:
|
||||
key (str, optional): The tag key to search for.
|
||||
category (str, optional): The category of tag
|
||||
to search for. If not set, uncategorized
|
||||
tags will be searched.
|
||||
|
||||
Returns:
|
||||
matches (list): List of Players with tags matching
|
||||
the search criteria, or an empty list if no
|
||||
matches were found.
|
||||
|
||||
"""
|
||||
return PlayerDB.objects.get_by_tag(key=key, category=category)
|
||||
def search_script_tag(key=None, category=None):
|
||||
"""
|
||||
Find script based on tag or category.
|
||||
|
||||
Args:
|
||||
key (str, optional): The tag key to search for.
|
||||
category (str, optional): The category of tag
|
||||
to search for. If not set, uncategorized
|
||||
tags will be searched.
|
||||
|
||||
Returns:
|
||||
matches (list): List of Scripts with tags matching
|
||||
the search criteria, or an empty list if no
|
||||
matches were found.
|
||||
|
||||
"""
|
||||
return ScriptDB.objects.get_by_tag(key=key, category=category)
|
||||
def search_channel_tag(key=None, category=None):
|
||||
"""
|
||||
Find channel based on tag or category.
|
||||
|
||||
Args:
|
||||
key (str, optional): The tag key to search for.
|
||||
category (str, optional): The category of tag
|
||||
to search for. If not set, uncategorized
|
||||
tags will be searched.
|
||||
|
||||
Returns:
|
||||
matches (list): List of Channels with tags matching
|
||||
the search criteria, or an empty list if no
|
||||
matches were found.
|
||||
|
||||
"""
|
||||
return Channel.objects.get_by_tag(key=key, category=category)
|
||||
|
||||
# search for tag objects
|
||||
# search for tag objects (not the objects they are attached to
|
||||
search_tag_object = ObjectDB.objects.get_tag
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue