Added category keyword to AttributeHandler's all() and clear() methods.

This commit is contained in:
Griatch 2013-08-25 19:15:27 +02:00
parent 48ddabdf25
commit 0a42b73824
3 changed files with 17 additions and 9 deletions

View file

@ -568,9 +568,9 @@ class ObjectDB(TypedObject):
if use_nicks: if use_nicks:
nicktype = "object" nicktype = "object"
# get all valid nicks to search # get all valid nicks to search
nicks = self.nicks.get(category="object_nick_%s" % nicktype) nicks = self.nicks.all(category="object_nick_%s" % nicktype)
if self.has_player: if self.has_player:
pnicks = self.nicks.get(category="player_nick_%s" % nicktype) pnicks = self.nicks.all(category="player_nick_%s" % nicktype)
nicks = nicks + pnicks nicks = nicks + pnicks
for nick in nicks: for nick in nicks:
if searchdata == nick.db_key: if searchdata == nick.db_key:

View file

@ -49,7 +49,7 @@ from src.server import caches
from src.server.caches import hashid from src.server.caches import hashid
from src.utils import logger, create from src.utils import logger, create
class _OOBTracker(Script): class _OOBTrackerScript(Script):
""" """
Active tracker script, handles subscriptions Active tracker script, handles subscriptions
""" """

View file

@ -388,19 +388,23 @@ class AttributeHandler(object):
del_attr_cache(self.obj, attr.db_key) del_attr_cache(self.obj, attr.db_key)
attr.delete() attr.delete()
def clear(self, accessing_obj=None, default_access=True): def clear(self, category=None, accessing_obj=None, default_access=True):
""" """
Remove all Attributes on this object. If accessing_obj is Remove all Attributes on this object. If accessing_obj is
given, check the 'attredit' lock on each Attribute before given, check the 'attredit' lock on each Attribute before
continuing. If not given, skip check. continuing. If not given, skip check.
""" """
for attr in _GA(self.obj, self._m2m_fieldname).all(): if category==None:
all_attr = _GA(self.obj, self._m2m_fieldname).all()
else:
all_attrs = _GA(self.obj, self._m2m_fieldname).filter(db_category=category)
for attr in all_attrs:
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)
attr.delete() attr.delete()
def all(self, accessing_obj=None, default_access=True): def all(self, category=None, accessing_obj=None, default_access=True):
""" """
Return all Attribute objects on this object. Return all Attribute objects on this object.
@ -408,10 +412,14 @@ class AttributeHandler(object):
each attribute before returning them. If not given, this each attribute before returning them. If not given, this
check is skipped. check is skipped.
""" """
if accessing_obj: if category==None:
return [attr for attr in _GA(self.obj, self._m2m_fieldname).all() if attr.access(accessing_obj, self._attrread, default=default_access)] all_attrs = _GA(self.obj, self._m2m_fieldname).all()
else: else:
return list(_GA(self.obj, self._m2m_fieldname).all()) all_attrs = _GA(self.obj, self._m2m_fieldname).filter(db_category=category)
if accessing_obj:
return [attr for attr in all_attrs if attr.access(accessing_obj, self._attrread, default=default_access)]
else:
return list(all_attrs)
class NickHandler(AttributeHandler): class NickHandler(AttributeHandler):
""" """