General database operations works with reworked, proxy-based typeclass system.

This commit is contained in:
Griatch 2014-12-22 14:14:21 +01:00
parent 1be49e7bea
commit 14086e3b3d
3 changed files with 10 additions and 6 deletions

View file

@ -279,6 +279,7 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
class TypeclassManager(TypedObjectManager):
def get(self, **kwargs):
"""
Overload the standard get. This will limit itself to only

View file

@ -234,7 +234,7 @@ class AttributeHandler(object):
"Initialize handler"
self.obj = obj
self._objid = obj.id
self._model = to_str(obj.__class__.__name__.lower())
self._model = to_str(obj.__dbclass__.__name__.lower())
self._cache = None
def _recache(self):
@ -1091,6 +1091,7 @@ class TypedObject(SharedMemoryModel):
def __init__(self, *args, **kwargs):
typeclass_path = kwargs.pop("typeclass", None)
super(TypedObject, self).__init__(*args, **kwargs)
self.__dbclass__ = self._meta.proxy_for_model
if typeclass_path:
self.__class__ = self._import_class(typeclass_path)
self.db_typclass_path = typeclass_path
@ -1368,6 +1369,13 @@ class TypedObject(SharedMemoryModel):
self._is_deleted = True
super(TypedObject, self).delete()
def save(self, *args, **kwargs):
"Block saving non-proxy typeclassed objects"
if not self._meta.proxy:
raise RuntimeError("Don't create instances of %s, "
"use its child typeclasses instead." % self.__class__.__name__)
super(TypedObject, self).save(*args, **kwargs)
#
# Memory management
#

View file

@ -312,11 +312,6 @@ class SharedMemoryModel(Model):
def save(self, *args, **kwargs):
"save method tracking process/thread issues"
# don't allow saving base objects
if not self._meta.proxy:
raise RuntimeError("Don't create instances of %s, "
"use its child typeclasses instead." % self.__class__.__name__)
if _IS_SUBPROCESS:
# we keep a store of objects modified in subprocesses so
# we know to update their caches in the central process