Merge branch 'master' into develop

This commit is contained in:
Griatch 2018-01-06 20:14:02 +01:00
commit a12a5d7445
3 changed files with 32 additions and 33 deletions

View file

@ -2722,7 +2722,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
def _show_prototypes(prototypes): def _show_prototypes(prototypes):
"""Helper to show a list of available prototypes""" """Helper to show a list of available prototypes"""
prots = ", ".join(sorted(prototypes.keys())) prots = ", ".join(sorted(prototypes.keys()))
return "\nAvailable prototypes (case sensistive): %s" % ( return "\nAvailable prototypes (case sensitive): %s" % (
"\n" + utils.fill(prots) if prots else "None") "\n" + utils.fill(prots) if prots else "None")
prototypes = spawn(return_prototypes=True) prototypes = spawn(return_prototypes=True)

View file

@ -355,15 +355,16 @@ class ChannelDBManager(TypedObjectManager):
channel (Channel or None): A channel match. channel (Channel or None): A channel match.
""" """
# first check the channel key dbref = self.dbref(channelkey)
channels = self.filter(db_key__iexact=channelkey) if dbref:
if not channels: try:
# also check aliases return self.get(id=dbref)
channels = [channel for channel in self.all() except self.model.DoesNotExist:
if channelkey in channel.aliases.all()] pass
if channels: results = self.filter(Q(db_key__iexact=channelkey) |
return channels[0] Q(db_tags__db_tagtype__iexact="alias",
return None db_tags__db_key__iexact=channelkey)).distinct()
return results[0] if results else None
def get_subscriptions(self, subscriber): def get_subscriptions(self, subscriber):
""" """
@ -393,26 +394,20 @@ class ChannelDBManager(TypedObjectManager):
case sensitive) match. case sensitive) match.
""" """
channels = [] dbref = self.dbref(ostring)
if not ostring: if dbref:
return channels try:
try: return self.get(id=dbref)
# try an id match first except self.model.DoesNotExist:
dbref = int(ostring.strip('#')) pass
channels = self.filter(id=dbref) if exact:
except Exception: channels = self.filter(Q(db_key__iexact=ostring) |
# Usually because we couldn't convert to int - not a dbref Q(db_tags__db_tagtype__iexact="alias",
pass db_tags__db_key__iexact=ostring)).distinct()
if not channels: else:
# no id match. Search on the key. channels = self.filter(Q(db_key__icontains=ostring) |
if exact: Q(db_tags__db_tagtype__iexact="alias",
channels = self.filter(db_key__iexact=ostring) db_tags__db_key__icontains=ostring)).distinct()
else:
channels = self.filter(db_key__icontains=ostring)
if not channels:
# still no match. Search by alias.
channels = [channel for channel in self.all()
if ostring.lower() in [a.lower for a in channel.aliases.all()]]
return channels return channels
# back-compatibility alias # back-compatibility alias
channel_search = search_channel channel_search = search_channel

View file

@ -76,10 +76,14 @@ class ObjectDBManager(TypedObjectManager):
# simplest case - search by dbref # simplest case - search by dbref
dbref = self.dbref(ostring) dbref = self.dbref(ostring)
if dbref: if dbref:
return dbref try:
return self.get(id=dbref)
except self.model.DoesNotExist:
pass
# not a dbref. Search by name. # not a dbref. Search by name.
cand_restriction = candidates is not None and Q(pk__in=[_GA(obj, "id") for obj in make_iter(candidates) cand_restriction = candidates is not None and Q(
if obj]) or Q() pk__in=[_GA(obj, "id") for obj in make_iter(candidates) if obj]) or Q()
if exact: if exact:
return self.filter(cand_restriction & Q(db_account__username__iexact=ostring)) return self.filter(cand_restriction & Q(db_account__username__iexact=ostring))
else: # fuzzy matching else: # fuzzy matching