Attribute cache is working, lots of other updates, but still not a cleanly updatable system. It seems the Attribute-migrations are not coming through properly. Fixed a misnamed table in the comm app.

This commit is contained in:
Griatch 2013-07-11 09:51:52 +02:00
parent 033344ad2c
commit 2b332c3b9a
16 changed files with 229 additions and 179 deletions

View file

@ -13,7 +13,7 @@ __all__ = ("ObjectManager",)
_GA = object.__getattribute__
# delayed import
_OBJATTR = None
_ATTR = None
# Try to use a custom way to parse id-tagged multimatches.
@ -139,15 +139,16 @@ class ObjectManager(TypedObjectManager):
#q = self.filter(cand_restriction & type_restriction & Q(objattribute__db_key=attribute_name) & Q(objattribute__db_value=attribute_value))
#return list(q)
if isinstance(attribute_value, (basestring, int, float, bool, long)):
return self.filter(cand_restriction & type_restriction & Q(objattribute__db_key=attribute_name, objattribute__db_value=attribute_value))
else:
# We have to loop for safety since the referenced lookup gives deepcopy error if attribute value is an object.
global _OBJATTR
if not _OBJATTR:
from src.objects.models import ObjAttribute as _OBJATTR
cands = list(self.filter(cand_restriction & type_restriction & Q(objattribute__db_key=attribute_name)))
return [_GA(attr, "db_obj") for attr in _OBJATTR.objects.filter(db_obj__in=cands, db_value=attribute_value)]
#if isinstance(attribute_value, (basestring, int, float, bool, long)):
return self.filter(cand_restriction & type_restriction & Q(db_attributes__db_key=attribute_name, db_attributes__db_value=attribute_value))
#else:
# # We have to loop for safety since the referenced lookup gives deepcopy error if attribute value is an object.
# global _ATTR
# if not _ATTR:
# from src.typeclasses.models import Attribute as _ATTR
# cands = list(self.filter(cand_restriction & type_restriction & Q(objattribute__db_key=attribute_name)))
# return [_ATTR.
# return [_GA(attr, "db_obj") for attr in _OBJATTR.objects.filter(db_obj__in=cands, db_value=attribute_value)]
@returns_typeclass_list
def get_objs_with_db_property(self, property_name, candidates=None):