mirror of
https://github.com/evennia/evennia.git
synced 2026-04-07 00:45:22 +02:00
Fixed errors in attributehandler that affected nicks. Test suite not validating yet.
This commit is contained in:
parent
642ae2faf9
commit
8b1afa7043
3 changed files with 38 additions and 21 deletions
|
|
@ -151,9 +151,9 @@ class TestGeneral(CommandTest):
|
|||
self.call(general.CmdNick(), "testalias = testaliasedstring1", "Nick set:")
|
||||
self.call(general.CmdNick(), "/player testalias = testaliasedstring2", "Nick set:")
|
||||
self.call(general.CmdNick(), "/object testalias = testaliasedstring3", "Nick set:")
|
||||
self.assertEqual(u"testaliasedstring1", self.char1.nicks.get_replace("testalias"))
|
||||
self.assertEqual(u"testaliasedstring2", self.char1.nicks.get_replace("testalias", category="player"))
|
||||
self.assertEqual(u"testaliasedstring3", self.char1.nicks.get_replace("testalias", category="object"))
|
||||
self.assertEqual(u"testaliasedstring1", self.char1.nicks.get("testalias"))
|
||||
self.assertEqual(u"testaliasedstring2", self.char1.nicks.get("testalias", category="player"))
|
||||
self.assertEqual(u"testaliasedstring3", self.char1.nicks.get("testalias", category="object"))
|
||||
self.call(general.CmdGet(), "Obj1", "You pick up Obj1.")
|
||||
self.call(general.CmdDrop(), "Obj1", "You drop Obj1.")
|
||||
self.call(general.CmdSay(), "Testing", "You say, \"Testing\"")
|
||||
|
|
@ -229,7 +229,8 @@ class TestBuilding(CommandTest):
|
|||
self.call(building.CmdUnLink(), "TestExit1", "Former exit TestExit1 no longer links anywhere.")
|
||||
self.call(building.CmdSetHome(), "Obj6 = Room6b", "Obj6's home location was changed from Room6")
|
||||
self.call(building.CmdListCmdSets(), "", "<DefaultCharacter (Union, prio 0, perm)>:")
|
||||
self.call(building.CmdTypeclass(), "Obj6 = src.objects.objects.Character", "Obj6's changed typeclass from src.objects.objects.Object to")
|
||||
self.call(building.CmdTypeclass(), "Obj6 = src.objects.objects.Character",
|
||||
"Obj6's changed typeclass from src.commands.default.tests.TestObjectClass to src.objects.objects.Character")
|
||||
self.call(building.CmdLock(), "Obj6 = test:perm(Immortals)", "Added lock 'test:perm(Immortals)' to Obj6.")
|
||||
self.call(building.CmdExamine(), "Obj6", "Name/key: Obj6")
|
||||
self.call(building.CmdFind(), "TestRoom1", "One Match")
|
||||
|
|
|
|||
|
|
@ -312,13 +312,16 @@ class AttributeHandler(object):
|
|||
accessing_obj is given, no check will be done.
|
||||
"""
|
||||
ret = []
|
||||
category_cond = Q(db_category__iexact=category) if category else Q()
|
||||
for keystr in make_iter(key):
|
||||
cachekey = "%s%s" % (category if category else "", keystr)
|
||||
attr_obj = get_attr_cache(self.obj, cachekey)
|
||||
key_cond = Q(db_key__iexact=keystr) if key!=None else Q()
|
||||
if not attr_obj:
|
||||
attr_obj = _GA(self.obj, "db_attributes").filter(key_cond & category_cond)
|
||||
key_cond = Q(db_key__iexact=keystr) if keystr!=None else Q()
|
||||
category_cond = Q(db_category__iexact=category) if category else Q()
|
||||
attr_obj = _GA(self.obj, self._m2m_fieldname).filter(key_cond & category_cond)
|
||||
if category and attr_obj and category.startswith("nick_"):
|
||||
o = attr_obj[0]
|
||||
print "attrhandler:", o.db_key, o.db_category, o.strvalue
|
||||
if not attr_obj:
|
||||
if raise_exception:
|
||||
raise AttributeError
|
||||
|
|
@ -354,7 +357,9 @@ class AttributeHandler(object):
|
|||
attr_obj = get_attr_cache(self.obj, cachekey)
|
||||
if not attr_obj:
|
||||
# check if attribute already exists
|
||||
attr_obj = _GA(self.obj, self._m2m_fieldname).filter(db_key__iexact=key)
|
||||
key_cond = Q(db_key__iexact=key) if key!=None else Q()
|
||||
category_cond = Q(db_category__iexact=category) if category else Q()
|
||||
attr_obj = _GA(self.obj, self._m2m_fieldname).filter(key_cond & category_cond)
|
||||
if attr_obj.count():
|
||||
# re-use old attribute object
|
||||
attr_obj = attr_obj[0]
|
||||
|
|
@ -364,6 +369,7 @@ class AttributeHandler(object):
|
|||
attr_obj = Attribute(db_key=key, db_category=category)
|
||||
attr_obj.save() # important
|
||||
_GA(self.obj, self._m2m_fieldname).add(attr_obj)
|
||||
set_attr_cache(self.obj, cachekey, attr_obj)
|
||||
if lockstring:
|
||||
attr_obj.locks.add(lockstring)
|
||||
# we shouldn't need to fear stale objects, the field signalling should catch all cases
|
||||
|
|
@ -381,12 +387,13 @@ class AttributeHandler(object):
|
|||
If accessing_obj is given, will check against the 'attredit' lock. If not given, this check is skipped.
|
||||
"""
|
||||
keys = make_iter(key)
|
||||
category_cond = Q(db_category__iexact=category) if category else Q()
|
||||
for attrkey in keys:
|
||||
matches = _GA(self.obj, self._m2m_fieldname).filter(Q(db_key__iexact=attrkey) & Q())
|
||||
if not matches and raise_exception:
|
||||
key_cond = Q(db_key__iexact=key) if key!=None else Q()
|
||||
category_cond = Q(db_category__iexact=category) if category else Q()
|
||||
attr_obj = _GA(self.obj, self._m2m_fieldname).filter(key_cond & category_cond)
|
||||
if not attr_obj and raise_exception:
|
||||
raise AttributeError
|
||||
for attr in matches:
|
||||
for attr in attr_obj:
|
||||
if accessing_obj and not attr.access(accessing_obj, self._attredit, default=default_access):
|
||||
continue
|
||||
del_attr_cache(self.obj, attr.db_key)
|
||||
|
|
@ -436,19 +443,28 @@ class NickHandler(AttributeHandler):
|
|||
def has(self, key, category="inputline"):
|
||||
categry = "nick_%s" % category
|
||||
return super(NickHandler, self).has(key, category=category)
|
||||
def add(self, key, replacement, category="inputline", **kwargs):
|
||||
"Add a new nick"
|
||||
category = "nick_%s" % category
|
||||
super(NickHandler, self).add(key, replacement, category=category, strattr=True, **kwargs)
|
||||
|
||||
def get(self, key=None, category="inputline", **kwargs):
|
||||
"Get the replacement value matching the given key and category"
|
||||
category = "nick_%s" % category
|
||||
return super(NickHandler, self).get(key=key, category=category, strattr=True, **kwargs)
|
||||
|
||||
def add(self, key, replacement, category="inputline", **kwargs):
|
||||
"Add a new nick"
|
||||
category = "nick_%s" % category
|
||||
super(NickHandler, self).add(key, replacement, category=category, strattr=True, **kwargs)
|
||||
|
||||
def remove(self, key, category="inputline", **kwargs):
|
||||
"Remove Nick with matching category"
|
||||
category = "nick_%s" % category
|
||||
super(NickHandler, self).remove(key, category=category, **kwargs)
|
||||
|
||||
def all(self, category=None):
|
||||
"Return all attributes with nick_* category"
|
||||
if category:
|
||||
category = "nick_%s" % category
|
||||
return super(NickHandler, self).all(category=category)
|
||||
return _GA(self.obj, self._m2m_fieldname).filter(db_category__startswith="nick_")
|
||||
|
||||
#------------------------------------------------------------
|
||||
#
|
||||
|
|
|
|||
|
|
@ -175,8 +175,8 @@ class TypeClass(object):
|
|||
dbobj.dbid,
|
||||
dbobj.typeclass_path,))
|
||||
|
||||
# def __str__(self):
|
||||
# "represent the object"
|
||||
# return _GA(self, "key")
|
||||
# def __unicode__(self):
|
||||
# return u"%s" % _GA(self, "key")
|
||||
def __str__(self):
|
||||
"represent the object"
|
||||
return self.key
|
||||
def __unicode__(self):
|
||||
return u"%s" % self.key
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue