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_script = None
|
||||||
search_player = None
|
search_player = None
|
||||||
search_channel = None
|
search_channel = None
|
||||||
|
search_message = None
|
||||||
search_help = None
|
search_help = None
|
||||||
search_tag = None
|
search_tag = None
|
||||||
|
|
||||||
|
|
@ -73,6 +74,10 @@ ansi = None
|
||||||
spawn = None
|
spawn = None
|
||||||
managers = None
|
managers = None
|
||||||
contrib = None
|
contrib = None
|
||||||
|
EvMenu = None
|
||||||
|
EvTable = None
|
||||||
|
EvForm = None
|
||||||
|
EvEditor = None
|
||||||
|
|
||||||
# Handlers
|
# Handlers
|
||||||
SESSION_HANDLER = None
|
SESSION_HANDLER = None
|
||||||
|
|
@ -150,6 +155,7 @@ def _init():
|
||||||
from .utils.search import search_object
|
from .utils.search import search_object
|
||||||
from .utils.search import search_script
|
from .utils.search import search_script
|
||||||
from .utils.search import search_player
|
from .utils.search import search_player
|
||||||
|
from .utils.search import search_message
|
||||||
from .utils.search import search_channel
|
from .utils.search import search_channel
|
||||||
from .utils.search import search_help
|
from .utils.search import search_help
|
||||||
from .utils.search import search_tag
|
from .utils.search import search_tag
|
||||||
|
|
@ -170,6 +176,10 @@ def _init():
|
||||||
from .utils import ansi
|
from .utils import ansi
|
||||||
from .utils.spawner import spawn
|
from .utils.spawner import spawn
|
||||||
from . import contrib
|
from . import contrib
|
||||||
|
from .utils.evmenu import EvMenu
|
||||||
|
from .utils.evtable import EvTable
|
||||||
|
from .utils.evform import EvForm
|
||||||
|
from .utils.eveditor import EvEditor
|
||||||
|
|
||||||
# handlers
|
# handlers
|
||||||
from .scripts.tickerhandler import TICKER_HANDLER
|
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)
|
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
|
Search the message database for particular messages. At least
|
||||||
one of the arguments must be given to do a search.
|
one of the arguments must be given to do a search.
|
||||||
|
|
@ -309,7 +309,8 @@ class MsgManager(TypedObjectManager):
|
||||||
fulltext_restrict = Q()
|
fulltext_restrict = Q()
|
||||||
# execute the query
|
# execute the query
|
||||||
return list(self.filter(sender_restrict & receiver_restrict & fulltext_restrict))
|
return list(self.filter(sender_restrict & receiver_restrict & fulltext_restrict))
|
||||||
|
# back-compatibility alias
|
||||||
|
message_search = search_message
|
||||||
|
|
||||||
#
|
#
|
||||||
# Channel manager
|
# Channel manager
|
||||||
|
|
@ -383,7 +384,7 @@ class ChannelDBManager(TypedObjectManager):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@returns_typeclass_list
|
@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.
|
Search the channel database for a particular channel.
|
||||||
|
|
||||||
|
|
@ -413,6 +414,8 @@ class ChannelDBManager(TypedObjectManager):
|
||||||
if ostring.lower() in [a.lower
|
if ostring.lower() in [a.lower
|
||||||
for a in channel.aliases.all()]]
|
for a in channel.aliases.all()]]
|
||||||
return channels
|
return channels
|
||||||
|
# back-compatibility alias
|
||||||
|
channel_search = search_channel
|
||||||
|
|
||||||
class ChannelManager(ChannelDBManager, TypeclassManager):
|
class ChannelManager(ChannelDBManager, TypeclassManager):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -291,7 +291,7 @@ class ObjectDBManager(TypedObjectManager):
|
||||||
# main search methods and helper functions
|
# main search methods and helper functions
|
||||||
|
|
||||||
@returns_typeclass_list
|
@returns_typeclass_list
|
||||||
def object_search(self, searchdata,
|
def search_object(self, searchdata,
|
||||||
attribute_name=None,
|
attribute_name=None,
|
||||||
typeclass=None,
|
typeclass=None,
|
||||||
candidates=None,
|
candidates=None,
|
||||||
|
|
@ -412,6 +412,8 @@ class ObjectDBManager(TypedObjectManager):
|
||||||
pass
|
pass
|
||||||
# return a list (possibly empty)
|
# return a list (possibly empty)
|
||||||
return matches
|
return matches
|
||||||
|
# alias for backwards compatibility
|
||||||
|
object_search = search_object
|
||||||
|
|
||||||
#
|
#
|
||||||
# ObjectManager Copy method
|
# ObjectManager Copy method
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,7 @@ class PlayerDBManager(TypedObjectManager, UserManager):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@returns_typeclass_list
|
@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
|
Searches for a particular player by name or
|
||||||
database id.
|
database id.
|
||||||
|
|
@ -182,7 +182,8 @@ class PlayerDBManager(TypedObjectManager, UserManager):
|
||||||
return self.filter(**query)
|
return self.filter(**query)
|
||||||
else:
|
else:
|
||||||
return self.filter(**query)
|
return self.filter(**query)
|
||||||
|
# back-compatibility alias
|
||||||
|
player_search = search_player
|
||||||
|
|
||||||
class PlayerManager(PlayerDBManager, TypeclassManager):
|
class PlayerManager(PlayerDBManager, TypeclassManager):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -217,7 +217,7 @@ class ScriptDBManager(TypedObjectManager):
|
||||||
return nr_started, nr_stopped
|
return nr_started, nr_stopped
|
||||||
|
|
||||||
@returns_typeclass_list
|
@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.
|
Search for a particular script.
|
||||||
|
|
||||||
|
|
@ -245,6 +245,8 @@ class ScriptDBManager(TypedObjectManager):
|
||||||
timed_restriction = only_timed and Q(interval__gt=0) or Q()
|
timed_restriction = only_timed and Q(interval__gt=0) or Q()
|
||||||
scripts = self.filter(timed_restriction & obj_restriction & Q(db_key__iexact=ostring))
|
scripts = self.filter(timed_restriction & obj_restriction & Q(db_key__iexact=ostring))
|
||||||
return scripts
|
return scripts
|
||||||
|
# back-compatibility alias
|
||||||
|
script_search = search_script
|
||||||
|
|
||||||
def copy_script(self, original_script, new_key=None, new_obj=None, new_locks=None):
|
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,
|
def __init__(self, caller, loadfunc=None, savefunc=None,
|
||||||
quitfunc=None, key="", persistent=False):
|
quitfunc=None, key="", persistent=False):
|
||||||
"""
|
"""
|
||||||
|
Launches a full in-game line editor, mimicking the functionality of VIM.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
caller (Object): Who is using the editor.
|
caller (Object): Who is using the editor.
|
||||||
loadfunc (callable, optional): This will be called as
|
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
|
# Note that this returns the object attached to the tag, not the tag
|
||||||
# object itself (this is usually what you want)
|
# 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)
|
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):
|
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)
|
return PlayerDB.objects.get_by_tag(key=key, category=category)
|
||||||
def search_script_tag(key=None, category=None):
|
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)
|
return ScriptDB.objects.get_by_tag(key=key, category=category)
|
||||||
def search_channel_tag(key=None, category=None):
|
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)
|
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
|
search_tag_object = ObjectDB.objects.get_tag
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue