2010-08-29 18:46:58 +00:00
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
This is a convenient container gathering all the main
|
2012-10-14 12:06:42 +02:00
|
|
|
search methods for the various database tables.
|
2010-08-29 18:46:58 +00:00
|
|
|
|
2012-10-14 12:06:42 +02:00
|
|
|
It is intended to be used e.g. as
|
2010-08-29 18:46:58 +00:00
|
|
|
|
|
|
|
|
> from src.utils import search
|
|
|
|
|
> match = search.objects(...)
|
|
|
|
|
|
|
|
|
|
Note that this is not intended to be a complete listing of all search
|
|
|
|
|
methods! You need to refer to the respective manager to get all
|
|
|
|
|
possible search methods. To get to the managers from your code, import
|
2012-10-14 12:06:42 +02:00
|
|
|
the database model and call its 'objects' property.
|
2010-08-29 18:46:58 +00:00
|
|
|
|
|
|
|
|
Also remember that all commands in this file return lists (also if
|
|
|
|
|
there is only one match) unless noted otherwise.
|
|
|
|
|
|
2012-10-14 12:06:42 +02:00
|
|
|
Example: To reach the search method 'get_object_with_user'
|
2010-08-29 18:46:58 +00:00
|
|
|
in src/objects/managers.py:
|
|
|
|
|
|
|
|
|
|
> from src.objects.models import ObjectDB
|
|
|
|
|
> match = Object.objects.get_object_with_user(...)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
# Import the manager methods to be wrapped
|
|
|
|
|
|
2011-04-23 11:54:08 +00:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
|
|
|
|
|
2012-03-25 17:01:27 +02:00
|
|
|
# limit symbol import from API
|
2012-03-25 17:39:45 +02:00
|
|
|
__all__ = ("search_object", "search_player", "search_script", "search_message", "search_channel", "search_help_entry")
|
2012-03-25 17:01:27 +02:00
|
|
|
|
|
|
|
|
|
2011-04-23 11:54:08 +00:00
|
|
|
# import objects this way to avoid circular import problems
|
|
|
|
|
ObjectDB = ContentType.objects.get(app_label="objects", model="objectdb").model_class()
|
|
|
|
|
PlayerDB = ContentType.objects.get(app_label="players", model="playerdb").model_class()
|
|
|
|
|
ScriptDB = ContentType.objects.get(app_label="scripts", model="scriptdb").model_class()
|
|
|
|
|
Msg = ContentType.objects.get(app_label="comms", model="msg").model_class()
|
|
|
|
|
Channel = ContentType.objects.get(app_label="comms", model="channel").model_class()
|
|
|
|
|
HelpEntry = ContentType.objects.get(app_label="help", model="helpentry").model_class()
|
2010-08-29 18:46:58 +00:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Search objects as a character
|
2012-10-14 12:06:42 +02:00
|
|
|
#
|
2010-08-29 18:46:58 +00:00
|
|
|
# NOTE: A more powerful wrapper of this method
|
|
|
|
|
# is reachable from within each command class
|
2012-10-14 12:06:42 +02:00
|
|
|
# by using self.caller.search()!
|
2010-08-29 18:46:58 +00:00
|
|
|
#
|
2011-04-24 11:26:51 +00:00
|
|
|
# def object_search(self, ostring, caller=None,
|
2012-10-14 12:06:42 +02:00
|
|
|
# candidates=None,
|
2010-08-29 18:46:58 +00:00
|
|
|
# attribute_name=None):
|
|
|
|
|
# """
|
|
|
|
|
# Search as an object and return results.
|
2012-10-14 12:06:42 +02:00
|
|
|
#
|
2010-08-29 18:46:58 +00:00
|
|
|
# ostring: (string) The string to compare names against.
|
2012-10-14 12:06:42 +02:00
|
|
|
# Can be a dbref. If name is appended by *, a player is searched for.
|
2011-04-24 11:26:51 +00:00
|
|
|
# caller: (Object) The object performing the search.
|
2012-10-14 12:06:42 +02:00
|
|
|
# candidates (list of Objects): restrict search only to those objects
|
2010-08-29 18:46:58 +00:00
|
|
|
# attribute_name: (string) Which attribute to search in each object.
|
2012-10-14 12:06:42 +02:00
|
|
|
# If None, the default 'name' attribute is used.
|
2010-08-29 18:46:58 +00:00
|
|
|
# """
|
|
|
|
|
|
2012-03-25 17:39:45 +02:00
|
|
|
search_object = ObjectDB.objects.object_search
|
|
|
|
|
search_objects = search_object
|
2012-03-25 17:01:27 +02:00
|
|
|
objects = search_objects
|
2010-08-29 18:46:58 +00:00
|
|
|
#
|
2012-10-14 12:06:42 +02:00
|
|
|
# Search for players
|
2010-08-29 18:46:58 +00:00
|
|
|
#
|
|
|
|
|
# NOTE: Most usually you would do such searches from
|
2012-10-14 12:06:42 +02:00
|
|
|
# from inseide command definitions using
|
|
|
|
|
# self.caller.search() by appending an '*' to the
|
2010-08-29 18:46:58 +00:00
|
|
|
# beginning of the search criterion.
|
|
|
|
|
#
|
|
|
|
|
# def player_search(self, ostring):
|
|
|
|
|
# """
|
2012-10-14 12:06:42 +02:00
|
|
|
# Searches for a particular player by name or
|
2010-08-29 18:46:58 +00:00
|
|
|
# database id.
|
|
|
|
|
#
|
|
|
|
|
# ostring = a string or database id.
|
|
|
|
|
# """
|
|
|
|
|
|
2012-10-14 12:06:42 +02:00
|
|
|
search_player = PlayerDB.objects.player_search
|
2012-03-25 17:39:45 +02:00
|
|
|
search_players = search_player
|
2012-03-25 17:01:27 +02:00
|
|
|
players = search_players
|
2010-08-29 18:46:58 +00:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Searching for scripts
|
|
|
|
|
#
|
|
|
|
|
# def script_search(self, ostring, obj=None, only_timed=False):
|
|
|
|
|
# """
|
|
|
|
|
# Search for a particular script.
|
2012-10-14 12:06:42 +02:00
|
|
|
#
|
2010-08-29 18:46:58 +00:00
|
|
|
# ostring - search criterion - a script ID or key
|
|
|
|
|
# obj - limit search to scripts defined on this object
|
|
|
|
|
# only_timed - limit search only to scripts that run
|
2012-10-14 12:06:42 +02:00
|
|
|
# on a timer.
|
2010-08-29 18:46:58 +00:00
|
|
|
# """
|
|
|
|
|
|
2012-03-25 17:39:45 +02:00
|
|
|
search_script = ScriptDB.objects.script_search
|
|
|
|
|
search_scripts = search_script
|
2012-03-25 17:01:27 +02:00
|
|
|
scripts = search_scripts
|
2010-08-29 18:46:58 +00:00
|
|
|
#
|
|
|
|
|
# Searching for communication messages
|
|
|
|
|
#
|
|
|
|
|
#
|
2012-10-14 12:06:42 +02:00
|
|
|
# def message_search(self, sender=None, receiver=None, channel=None, freetext=None):
|
2010-08-29 18:46:58 +00:00
|
|
|
# """
|
2012-10-14 12:06:42 +02:00
|
|
|
# Search the message database for particular messages. At least one
|
|
|
|
|
# of the arguments must be given to do a search.
|
2010-08-29 18:46:58 +00:00
|
|
|
#
|
|
|
|
|
# sender - get messages sent by a particular player
|
|
|
|
|
# receiver - get messages received by a certain player
|
2012-10-14 12:06:42 +02:00
|
|
|
# channel - get messages sent to a particular channel
|
|
|
|
|
# freetext - Search for a text string in a message.
|
2010-08-29 18:46:58 +00:00
|
|
|
# NOTE: This can potentially be slow, so make sure to supply
|
2012-10-14 12:06:42 +02:00
|
|
|
# one of the other arguments to limit the search.
|
|
|
|
|
# """
|
2010-08-29 18:46:58 +00:00
|
|
|
|
2012-03-25 17:39:45 +02:00
|
|
|
search_message = Msg.objects.message_search
|
|
|
|
|
search_messages = search_message
|
2012-03-25 17:01:27 +02:00
|
|
|
messages = search_messages
|
2010-08-29 18:46:58 +00:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Search for Communication Channels
|
|
|
|
|
#
|
|
|
|
|
# def channel_search(self, ostring)
|
|
|
|
|
# """
|
|
|
|
|
# Search the channel database for a particular channel.
|
|
|
|
|
#
|
|
|
|
|
# ostring - the key or database id of the channel.
|
|
|
|
|
# """
|
|
|
|
|
|
2012-03-25 17:39:45 +02:00
|
|
|
search_channel = Channel.objects.channel_search
|
|
|
|
|
search_channels = search_channel
|
2012-03-25 17:01:27 +02:00
|
|
|
channels = search_channels
|
2010-08-29 18:46:58 +00:00
|
|
|
|
|
|
|
|
#
|
2012-10-14 12:06:42 +02:00
|
|
|
# Find help entry objects.
|
2010-08-29 18:46:58 +00:00
|
|
|
#
|
|
|
|
|
# def search_help(self, ostring, help_category=None):
|
|
|
|
|
# """
|
|
|
|
|
# Retrieve a search entry object.
|
|
|
|
|
#
|
|
|
|
|
# ostring - the help topic to look for
|
|
|
|
|
# category - limit the search to a particular help topic
|
|
|
|
|
# """
|
|
|
|
|
|
2012-10-14 12:06:42 +02:00
|
|
|
search_help_entry = HelpEntry.objects.search_help
|
2012-03-25 17:39:45 +02:00
|
|
|
search_help_entries = search_help_entry
|
2012-03-25 17:01:27 +02:00
|
|
|
help_entries = search_help_entries
|