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

@ -6,12 +6,13 @@
from django import forms
from django.conf import settings
from django.contrib import admin
from src.objects.models import ObjAttribute, ObjectDB, ObjectNick, Alias
from src.typeclases.models import Attribute
from src.objects.models import ObjectDB, ObjectNick, Alias
from src.utils.utils import mod_import
class ObjAttributeInline(admin.TabularInline):
model = ObjAttribute
class AttributeInline(admin.TabularInline):
model = Attribute
fields = ('db_key', 'db_value')
extra = 0
@ -80,7 +81,7 @@ class ObjectDBAdmin(admin.ModelAdmin):
)
#deactivated temporarily, they cause empty objects to be created in admin
#inlines = [AliasInline, ObjAttributeInline]
#inlines = [AliasInline, AttributeInline]
# Custom modification to give two different forms wether adding or not.

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):

View file

@ -17,7 +17,6 @@ transparently through the decorating TypeClass.
import traceback
from django.db import models
from django.conf import settings
from django.db.models.signals import m2m_changed
from src.utils.idmapper.models import SharedMemoryModel
from src.typeclasses.models import Attribute, TypedObject, TypeNick, TypeNickHandler
@ -49,26 +48,6 @@ _ME = _("me")
_SELF = _("self")
_HERE = _("here")
#------------------------------------------------------------
#
# ObjAttribute
#
#------------------------------------------------------------
#class ObjAttribute(Attribute):
# "Attributes for ObjectDB objects."
# db_obj = models.ForeignKey("ObjectDB")
#
# class Meta:
# "Define Django meta options"
# verbose_name = "Object Attribute"
# verbose_name_plural = "Object Attributes"
#
# attach the cache handlers
#post_init.connect(attr_post_init, sender=ObjAttribute, dispatch_uid="objattrcache")
#pre_delete.connect(attr_pre_delete, sender=ObjAttribute, dispatch_uid="objattrcache")
#------------------------------------------------------------
#
# Alias

View file

@ -34,19 +34,20 @@ class TestObjAttrs(TestCase):
"""
Test aspects of ObjAttributes
"""
def setUp(self):
"set up the test"
self.attr = models.ObjAttribute()
self.obj1 = create.create_object(objects.Object, key="testobj1", location=None)
self.obj2 = create.create_object(objects.Object, key="testobj2", location=self.obj1)
def test_store_str(self):
hstring = u"sdfv00=97sfjs842 ivfjlQKFos9GF^8dddsöäå-?%"
self.obj1.db.testattr = hstring
self.assertEqual(hstring, self.obj1.db.testattr)
def test_store_obj(self):
self.obj1.db.testattr = self.obj2
self.assertEqual(self.obj2 ,self.obj1.db.testattr)
self.assertEqual(self.obj2.location, self.obj1.db.testattr.location)
pass
# def setUp(self):
# "set up the test"
# self.attr = models.ObjAttribute()
# self.obj1 = create.create_object(objects.Object, key="testobj1", location=None)
# self.obj2 = create.create_object(objects.Object, key="testobj2", location=self.obj1)
# def test_store_str(self):
# hstring = u"sdfv00=97sfjs842 ivfjlQKFos9GF^8dddsöäå-?%"
# self.obj1.db.testattr = hstring
# self.assertEqual(hstring, self.obj1.db.testattr)
# def test_store_obj(self):
# self.obj1.db.testattr = self.obj2
# self.assertEqual(self.obj2 ,self.obj1.db.testattr)
# self.assertEqual(self.obj2.location, self.obj1.db.testattr.location)
def suite():
"""