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(), "testalias = testaliasedstring1", "Nick set:")
|
||||||
self.call(general.CmdNick(), "/player testalias = testaliasedstring2", "Nick set:")
|
self.call(general.CmdNick(), "/player testalias = testaliasedstring2", "Nick set:")
|
||||||
self.call(general.CmdNick(), "/object testalias = testaliasedstring3", "Nick set:")
|
self.call(general.CmdNick(), "/object testalias = testaliasedstring3", "Nick set:")
|
||||||
self.assertEqual(u"testaliasedstring1", self.char1.nicks.get_replace("testalias"))
|
self.assertEqual(u"testaliasedstring1", self.char1.nicks.get("testalias"))
|
||||||
self.assertEqual(u"testaliasedstring2", self.char1.nicks.get_replace("testalias", category="player"))
|
self.assertEqual(u"testaliasedstring2", self.char1.nicks.get("testalias", category="player"))
|
||||||
self.assertEqual(u"testaliasedstring3", self.char1.nicks.get_replace("testalias", category="object"))
|
self.assertEqual(u"testaliasedstring3", self.char1.nicks.get("testalias", category="object"))
|
||||||
self.call(general.CmdGet(), "Obj1", "You pick up Obj1.")
|
self.call(general.CmdGet(), "Obj1", "You pick up Obj1.")
|
||||||
self.call(general.CmdDrop(), "Obj1", "You drop Obj1.")
|
self.call(general.CmdDrop(), "Obj1", "You drop Obj1.")
|
||||||
self.call(general.CmdSay(), "Testing", "You say, \"Testing\"")
|
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.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.CmdSetHome(), "Obj6 = Room6b", "Obj6's home location was changed from Room6")
|
||||||
self.call(building.CmdListCmdSets(), "", "<DefaultCharacter (Union, prio 0, perm)>:")
|
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.CmdLock(), "Obj6 = test:perm(Immortals)", "Added lock 'test:perm(Immortals)' to Obj6.")
|
||||||
self.call(building.CmdExamine(), "Obj6", "Name/key: Obj6")
|
self.call(building.CmdExamine(), "Obj6", "Name/key: Obj6")
|
||||||
self.call(building.CmdFind(), "TestRoom1", "One Match")
|
self.call(building.CmdFind(), "TestRoom1", "One Match")
|
||||||
|
|
|
||||||
|
|
@ -312,13 +312,16 @@ class AttributeHandler(object):
|
||||||
accessing_obj is given, no check will be done.
|
accessing_obj is given, no check will be done.
|
||||||
"""
|
"""
|
||||||
ret = []
|
ret = []
|
||||||
category_cond = Q(db_category__iexact=category) if category else Q()
|
|
||||||
for keystr in make_iter(key):
|
for keystr in make_iter(key):
|
||||||
cachekey = "%s%s" % (category if category else "", keystr)
|
cachekey = "%s%s" % (category if category else "", keystr)
|
||||||
attr_obj = get_attr_cache(self.obj, cachekey)
|
attr_obj = get_attr_cache(self.obj, cachekey)
|
||||||
key_cond = Q(db_key__iexact=keystr) if key!=None else Q()
|
|
||||||
if not attr_obj:
|
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 not attr_obj:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise AttributeError
|
raise AttributeError
|
||||||
|
|
@ -354,7 +357,9 @@ class AttributeHandler(object):
|
||||||
attr_obj = get_attr_cache(self.obj, cachekey)
|
attr_obj = get_attr_cache(self.obj, cachekey)
|
||||||
if not attr_obj:
|
if not attr_obj:
|
||||||
# check if attribute already exists
|
# 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():
|
if attr_obj.count():
|
||||||
# re-use old attribute object
|
# re-use old attribute object
|
||||||
attr_obj = attr_obj[0]
|
attr_obj = attr_obj[0]
|
||||||
|
|
@ -364,6 +369,7 @@ class AttributeHandler(object):
|
||||||
attr_obj = Attribute(db_key=key, db_category=category)
|
attr_obj = Attribute(db_key=key, db_category=category)
|
||||||
attr_obj.save() # important
|
attr_obj.save() # important
|
||||||
_GA(self.obj, self._m2m_fieldname).add(attr_obj)
|
_GA(self.obj, self._m2m_fieldname).add(attr_obj)
|
||||||
|
set_attr_cache(self.obj, cachekey, attr_obj)
|
||||||
if lockstring:
|
if lockstring:
|
||||||
attr_obj.locks.add(lockstring)
|
attr_obj.locks.add(lockstring)
|
||||||
# we shouldn't need to fear stale objects, the field signalling should catch all cases
|
# 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.
|
If accessing_obj is given, will check against the 'attredit' lock. If not given, this check is skipped.
|
||||||
"""
|
"""
|
||||||
keys = make_iter(key)
|
keys = make_iter(key)
|
||||||
category_cond = Q(db_category__iexact=category) if category else Q()
|
|
||||||
for attrkey in keys:
|
for attrkey in keys:
|
||||||
matches = _GA(self.obj, self._m2m_fieldname).filter(Q(db_key__iexact=attrkey) & Q())
|
key_cond = Q(db_key__iexact=key) if key!=None else Q()
|
||||||
if not matches and raise_exception:
|
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
|
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):
|
if accessing_obj and not attr.access(accessing_obj, self._attredit, default=default_access):
|
||||||
continue
|
continue
|
||||||
del_attr_cache(self.obj, attr.db_key)
|
del_attr_cache(self.obj, attr.db_key)
|
||||||
|
|
@ -436,19 +443,28 @@ class NickHandler(AttributeHandler):
|
||||||
def has(self, key, category="inputline"):
|
def has(self, key, category="inputline"):
|
||||||
categry = "nick_%s" % category
|
categry = "nick_%s" % category
|
||||||
return super(NickHandler, self).has(key, category=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):
|
def get(self, key=None, category="inputline", **kwargs):
|
||||||
"Get the replacement value matching the given key and category"
|
"Get the replacement value matching the given key and category"
|
||||||
category = "nick_%s" % category
|
category = "nick_%s" % category
|
||||||
return super(NickHandler, self).get(key=key, category=category, strattr=True, **kwargs)
|
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):
|
def remove(self, key, category="inputline", **kwargs):
|
||||||
"Remove Nick with matching category"
|
"Remove Nick with matching category"
|
||||||
category = "nick_%s" % category
|
category = "nick_%s" % category
|
||||||
super(NickHandler, self).remove(key, category=category, **kwargs)
|
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.dbid,
|
||||||
dbobj.typeclass_path,))
|
dbobj.typeclass_path,))
|
||||||
|
|
||||||
# def __str__(self):
|
def __str__(self):
|
||||||
# "represent the object"
|
"represent the object"
|
||||||
# return _GA(self, "key")
|
return self.key
|
||||||
# def __unicode__(self):
|
def __unicode__(self):
|
||||||
# return u"%s" % _GA(self, "key")
|
return u"%s" % self.key
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue