From c0b5c506a4a8ba68a8cab82bc6dc6e52e59a6db5 Mon Sep 17 00:00:00 2001 From: Griatch Date: Fri, 12 Jul 2013 15:34:54 +0200 Subject: [PATCH] Removed a lot of old references to Aliases and Nicks. Still failing on @puppet. --- src/commands/default/building.py | 34 ++++----- src/locks/lockfuncs.py | 2 +- src/objects/objects.py | 2 +- src/typeclasses/models.py | 115 +++++++++++++++++-------------- src/utils/create.py | 2 +- 5 files changed, 85 insertions(+), 70 deletions(-) diff --git a/src/commands/default/building.py b/src/commands/default/building.py index 8492d41dfb..076714c56c 100644 --- a/src/commands/default/building.py +++ b/src/commands/default/building.py @@ -123,7 +123,7 @@ class CmdSetObjAlias(MuxCommand): return if self.rhs == None: # no =, so we just list aliases on object. - aliases = obj.aliases + aliases = obj.aliases.all() if aliases: caller.msg("Aliases for '%s': %s" % (obj.key, ", ".join(aliases))) else: @@ -136,22 +136,22 @@ class CmdSetObjAlias(MuxCommand): if not self.rhs: # we have given an empty =, so delete aliases - old_aliases = obj.aliases + old_aliases = obj.aliases.all() if old_aliases: caller.msg("Cleared aliases from %s: %s" % (obj.key, ", ".join(old_aliases))) - del obj.dbobj.aliases + obj.dbobj.db_aliases.clear() else: caller.msg("No aliases to clear.") return # merge the old and new aliases (if any) - old_aliases = obj.aliases + old_aliases = obj.aliases.all() new_aliases = [alias.strip().lower() for alias in self.rhs.split(',') if alias.strip()] # make the aliases only appear once old_aliases.extend(new_aliases) aliases = list(set(old_aliases)) # save back to object. - obj.aliases = aliases + obj.aliases.add(aliases) # we treat this as a re-caching (relevant for exits to re-build their exit commands with the correct aliases) caller.msg("Aliases for '%s' are now set to %s." % (obj.key, ", ".join(obj.aliases))) @@ -191,7 +191,7 @@ class CmdCopy(ObjManipCommand): if not from_obj: return to_obj_name = "%s_copy" % from_obj_name - to_obj_aliases = ["%s_copy" % alias for alias in from_obj.aliases] + to_obj_aliases = ["%s_copy" % alias for alias in from_obj.aliases.all()] copiedobj = ObjectDB.objects.copy_object(from_obj, new_key=to_obj_name, new_aliases=to_obj_aliases) if copiedobj: @@ -598,8 +598,8 @@ class CmdDig(ObjManipCommand): aliases=room["aliases"], report_to=caller) new_room.locks.add(lockstring) alias_string = "" - if new_room.aliases: - alias_string = " (%s)" % ", ".join(new_room.aliases) + if new_room.aliases.all(): + alias_string = " (%s)" % ", ".join(new_room.aliases.all()) room_string = "Created room %s(%s)%s of type %s." % (new_room, new_room.dbref, alias_string, typeclass) @@ -626,8 +626,8 @@ class CmdDig(ObjManipCommand): aliases=to_exit["aliases"], locks=lockstring, destination=new_room, report_to=caller) alias_string = "" - if new_to_exit.aliases: - alias_string = " (%s)" % ", ".join(new_to_exit.aliases) + if new_to_exit.aliases.all(): + alias_string = " (%s)" % ", ".join(new_to_exit.aliases.all()) exit_to_string = "\nCreated Exit from %s to %s: %s(%s)%s." exit_to_string = exit_to_string % (location.name, new_room.name, new_to_exit, new_to_exit.dbref, alias_string) @@ -651,8 +651,8 @@ class CmdDig(ObjManipCommand): new_room, aliases=back_exit["aliases"], locks=lockstring, destination=location, report_to=caller) alias_string = "" - if new_back_exit.aliases: - alias_string = " (%s)" % ", ".join(new_back_exit.aliases) + if new_back_exit.aliases.all(): + alias_string = " (%s)" % ", ".join(new_back_exit.aliases.all()) exit_back_string = "\nCreated Exit back from %s to %s: %s(%s)%s." exit_back_string = exit_back_string % (new_room.name, location.name, new_back_exit, new_back_exit.dbref, alias_string) @@ -979,7 +979,7 @@ class CmdName(ObjManipCommand): obj.name = newname astring = "" if aliases: - obj.aliases = aliases + [obj.aliases.add(alias) for alias in aliases] astring = " (%s)" % (", ".join(aliases)) # fix for exits - we need their exit-command to change name too if obj.destination: @@ -1037,7 +1037,7 @@ class CmdOpen(ObjManipCommand): if old_destination.id != destination.id: # reroute the old exit. exit_obj.destination = destination - exit_obj.aliases = exit_aliases + [exit_obj.aliases.add(alias) for alias in exit_aliases] string += " Rerouted its old destination '%s' to '%s' and changed aliases." % \ (old_destination.name, destination.name) else: @@ -1568,8 +1568,8 @@ class CmdExamine(ObjManipCommand): """ string = "\n{wName/key{n: {c%s{n (%s)" % (obj.name, obj.dbref) - if hasattr(obj, "aliases") and obj.aliases: - string += "\n{wAliases{n: %s" % (", ".join(utils.make_iter(obj.aliases))) + if hasattr(obj, "aliases") and obj.aliases.all(): + string += "\n{wAliases{n: %s" % (", ".join(utils.make_iter(obj.aliases.all()))) if hasattr(obj, "sessid") and obj.sessid: string += "\n{wsession{n: %s" % obj.sessid elif hasattr(obj, "sessions") and obj.sessions: @@ -1785,7 +1785,7 @@ class CmdFind(MuxCommand): nresults = results.count() if not nresults: # no matches on the keys. Try aliases instead. - results = results = ObjectDB.alias_set.related.model.objects.filter(db_key=searchstring) + results = ObjectDB.db_aliases.filter(db_key=searchstring) if "room" in switches: results = results.filter(db_obj__db_location__isnull=True) if "exit" in switches: diff --git a/src/locks/lockfuncs.py b/src/locks/lockfuncs.py index 162623c838..158d37d435 100644 --- a/src/locks/lockfuncs.py +++ b/src/locks/lockfuncs.py @@ -420,7 +420,7 @@ def holds(accessing_obj, accessed_obj, *args, **kwargs): return True objid = objid.lower() return any((True for obj in contents - if obj.key.lower() == objid or objid in [al.lower() for al in obj.aliases])) + if obj.key.lower() == objid or objid in [al.lower() for al in obj.aliases.all()])) if not args: # holds() - check if accessed_obj or accessed_obj.obj is held by accessing_obj try: diff --git a/src/objects/objects.py b/src/objects/objects.py index 6a748cdbb3..aa83900758 100644 --- a/src/objects/objects.py +++ b/src/objects/objects.py @@ -910,7 +910,7 @@ class Exit(Object): # create an exit command. cmd = ExitCommand(key=exidbobj.db_key.strip().lower(), - aliases=exidbobj.aliases, + aliases=exidbobj.aliases.all(), locks=str(exidbobj.locks), auto_help=False, destination=exidbobj.db_destination, diff --git a/src/typeclasses/models.py b/src/typeclasses/models.py index fe3e992eba..2995a39023 100644 --- a/src/typeclasses/models.py +++ b/src/typeclasses/models.py @@ -365,27 +365,29 @@ class TagHandler(object): def add(self, tag, category=None, data=None): "Add a new tag to the handler" - tag = tag.strip().lower() if tag!=None else None - category = "%s%s" % (self.prefix, category.strip.lower()) if category!=None else None - data = str(data) if data!=None else None - # this will only create tag if no matches existed beforehand (it will overload - # data on an existing tag since that is not considered part of making the tag unique) - tagobj = Tag.objects.create_tag(key=tag, category=category, data=data) - self.obj.db_tags.add(tagobj) + for tag in make_iter(tag): + tag = tag.strip().lower() if tag!=None else None + category = "%s%s" % (self.prefix, category.strip.lower()) if category!=None else None + data = str(data) if data!=None else None + # this will only create tag if no matches existed beforehand (it will overload + # data on an existing tag since that is not considered part of making the tag unique) + tagobj = Tag.objects.create_tag(key=tag, category=category, data=data) + self.obj.db_tags.add(tagobj) def remove(self, tag, category=None): "Remove a tag from the handler" - tag = tag.strip().lower() if tag!=None else None - category = "%s%s" % (self.prefix, category.strip.lower()) if category!=None else None - #TODO This does not delete the tag object itself. Maybe it should do that when no - # objects reference the tag anymore? - tagobj = self.obj.db_tags.filter(db_key=tag, db_category=category) - if tagobj: - self.obj.remove(tagobj[0]) + for tag in make_iter(tag): + tag = tag.strip().lower() if tag!=None else None + category = "%s%s" % (self.prefix, category.strip.lower()) if category!=None else None + #TODO This does not delete the tag object itself. Maybe it should do that when no + # objects reference the tag anymore? + tagobj = self.obj.db_tags.filter(db_key=tag, db_category=category) + if tagobj: + self.obj.remove(tagobj[0]) def all(self): "Get all tags in this handler" - return self.obj.db_tags.all().get_values("db_key") + return self.obj.db_tags.all().values_list("db_key") def __str__(self): return ",".join(self.all()) @@ -412,21 +414,23 @@ class AliasHandler(object): "Add a new nick to the handler" if not alias or not alias.strip(): return - alias = alias.strip() - # create a unique tag only if it didn't already exist - aliasobj = Tag.objects.create_tag(key=alias, category=self.category) - self.obj.db_tags.add(aliasobj) + for al in make_iter(alias): + al = al.strip() + # create a unique tag only if it didn't already exist + aliasobj = Tag.objects.create_tag(key=al, category=self.category) + self.obj.db_tags.add(aliasobj) def remove(self, alias): "Remove alias from handler." - aliasobj = Tag.objects.filter(db_key__iexact=alias.strip(), category=self.category).count() - #TODO note that this doesn't delete the tag itself. We might want to do this when no object - # uses it anymore ... - self.obj.db_tags.remove(aliasobj) + for alias in make_iter(alias): + aliasobj = Tag.objects.filter(db_key__iexact=alias.strip(), category=self.category).count() + #TODO note that this doesn't delete the tag itself. We might want to do this when no object + # uses it anymore ... + self.obj.db_tags.remove(aliasobj) def all(self): "Get all aliases in this handler" - return self.obj.db_tags.filter(db_category=self.category).get_values("db_key") + return list(self.obj.db_tags.filter(db_category=self.category).values_list("db_key")) def __str__(self): return ",".join(self.all()) @@ -466,27 +470,29 @@ class NickHandler(object): """ if not nick or not nick.strip(): return - nick = nick.strip() - real = realname - nick_type = "%s%s" % (self.prefix, nick_type.strip().lower()) - query = self.obj.db_liteattributes.filter(db_key__iexact=nick, db_category__iexact=nick_type) - if query.count(): - old_nick = query[0] - old_nick.db_data = real - old_nick.save() - else: - new_nick = LiteAttribute(db_key=nick, db_category=nick_type, db_data=real) - new_nick.save() - self.obj.db_liteattributes.add(new_nick) + for nick in make_iter(nick): + nick = nick.strip() + real = realname + nick_type = "%s%s" % (self.prefix, nick_type.strip().lower()) + query = self.obj.db_liteattributes.filter(db_key__iexact=nick, db_category__iexact=nick_type) + if query.count(): + old_nick = query[0] + old_nick.db_data = real + old_nick.save() + else: + new_nick = LiteAttribute(db_key=nick, db_category=nick_type, db_data=real) + new_nick.save() + self.obj.db_liteattributes.add(new_nick) def remove(self, nick, nick_type="inputline"): "Removes a previously stored nick" - nick = nick.strip() - nick_type = "%s%s" % (self.prefix, nick_type.strip().lower()) - query = self.obj.liteattributes.filter(db_key__iexact=nick, db_category__iexact=nick_type) - if query.count(): - # remove the found nick(s) - query.delete() + for nick in make_iter(nick): + nick = nick.strip() + nick_type = "%s%s" % (self.prefix, nick_type.strip().lower()) + query = self.obj.liteattributes.filter(db_key__iexact=nick, db_category__iexact=nick_type) + if query.count(): + # remove the found nick(s) + query.delete() def delete(self, *args, **kwargs): "alias wrapper" @@ -500,14 +506,23 @@ class NickHandler(object): If no nick is given, returns a list of all matching nick objects (LiteAttributes) on the object, or the empty list. """ - nick = nick.strip().lower() if nick!=None else None - nick_type = "%s%s" % (self.prefix, nick_type.strip().lower()) - if nick: - nicks = _GA(self.obj, "db_liteattributes").objects.filter(db_key=nick, db_category=nick_type).prefetch_related("db_data") - default = default if default!=None else nick - return nicks[0].db_data if nicks else default - else: - return list(self.obj.db_liteattributes.all()) + returns = [] + for nick in make_iter(nick): + nick = nick.strip().lower() if nick!=None else None + nick_type = "%s%s" % (self.prefix, nick_type.strip().lower()) + if nick: + nicks = _GA(self.obj, "db_liteattributes").objects.filter(db_key=nick, db_category=nick_type).prefetch_related("db_data") + default = default if default!=None else nick + return nicks[0].db_data if nicks else default + else: + returns.extend(list(self.obj.db_liteattributes.all())) + return returns + + def all(self): + "Get all nicks in this handler" + return list(self.obj.db_nicks.filter(db_category=self.category).values_list("db_key")) + + #------------------------------------------------------------ diff --git a/src/utils/create.py b/src/utils/create.py index 32e07dfa7c..3772538b08 100644 --- a/src/utils/create.py +++ b/src/utils/create.py @@ -129,7 +129,7 @@ def create_object(typeclass, key=None, location=None, if locks: new_object.locks.add(locks) if aliases: - new_object.aliases = aliases + new_object.aliases.add(aliases) # perform a move_to in order to display eventual messages. if home: