diff --git a/src/typeclasses/models.py b/src/typeclasses/models.py index 2412ebbad9..4a08940e91 100644 --- a/src/typeclasses/models.py +++ b/src/typeclasses/models.py @@ -541,10 +541,10 @@ class TypedObject(SharedMemoryModel): # typeclass' __getattribute__, since that one would # try to look back to this very database object.) typeclass = object.__getattribute__(self, 'typeclass') - #print " '%s' not on db --> Checking typeclass %s instead." % (propname, typeclass) if typeclass: - return object.__getattribute__(typeclass(self), propname) - raise + return object.__getattribute__(typeclass(self), propname) + else: + raise AttributeError #@property def dbref_get(self): @@ -595,15 +595,16 @@ class TypedObject(SharedMemoryModel): if not path: # this means we should get the default obj # without giving errors. - defpath = self.default_typeclass_path - typeclass = self._path_import(defpath) + defpath = object.__getattribute__(self, 'default_typeclass_path') + typeclass = object.__getattribute__(self, '_path_import')(defpath) + #typeclass = self._path_import(defpath) else: typeclass = TYPECLASS_CACHE.get(path, None) if typeclass: # we've imported this before. We're done. return typeclass # not in cache. Import anew. - typeclass = self._path_import(path) + typeclass = object.__getattribute__(self, "_path_import")(path) if not callable(typeclass): # given path failed to import, fallback to default. errstring = " %s" % typeclass # this is an error message @@ -611,12 +612,12 @@ class TypedObject(SharedMemoryModel): errstring += "\nThis seems to be just the path to a module. You need" errstring += " to specify the actual typeclass name inside the module too." errstring += "\n Typeclass '%s' failed to load." % path - defpath = self.default_typeclass_path + defpath = object.__getattribute__(self, default_typeclass_path) errstring += " Using Default class '%s'." % defpath self.db_typeclass_path = defpath self.save() logger.log_errmsg(errstring) - typeclass = self._path_import(defpath) + typeclass = object.__getattribute__(self, "_path_import")(defpath) errmsg(errstring) if not callable(typeclass): # if typeclass still doesn't exist, we're in trouble. @@ -628,7 +629,7 @@ class TypedObject(SharedMemoryModel): self.db_typeclass_path = defpath self.save() logger.log_errmsg(errstring) - typeclass = self._path_import(defpath) + typeclass = object.__getattribute__(self, "_path_import")(defpath) errmsg(errstring) else: TYPECLASS_CACHE[path] = typeclass diff --git a/src/typeclasses/typeclass.py b/src/typeclasses/typeclass.py index c18d81e6a9..c758046227 100644 --- a/src/typeclasses/typeclass.py +++ b/src/typeclasses/typeclass.py @@ -15,7 +15,7 @@ from django.conf import settings # To ensure the sanity of the model, there are a # few property names we won't allow the admin to -# set just like that. Note that these are *not* related +# set on the typeclass just like that. Note that these are *not* related # to *in-game* safety (if you can edit typeclasses you have # full access anyway), so no protection against changing # e.g. 'locks' or 'permissions' should go here. @@ -88,9 +88,9 @@ class TypeClass(object): cls = object.__getattribute__(self, '__class__') db_typeclass_path = "%s.%s" % (object.__getattribute__(cls, '__module__'), object.__getattribute__(cls, '__name__')) - if not dbobj.db_typeclass_path == db_typeclass_path: - dbobj.db_typeclass_path = db_typeclass_path - dbobj.save() + if not object.__getattribute__(dbobj, "db_typeclass_path") == db_typeclass_path: + object.__setattr__(dbobj, "db_typeclass_path", db_typeclass_path) + object.__getattribute__(dbobj, "save")() # (The inheriting typed object classes often extend this __init__ to # add handlers etc.) @@ -118,12 +118,10 @@ class TypeClass(object): return object.__getattribute__(self, propname) #print "get %s (dbobj:%s)" % (propname, type(dbobj)) try: - #print "Typeclass: looking for %s on dbobj %s" % (propname, dbobj) - #print " <-- dbobj" - return object.__getattribute__(dbobj, propname) + return object.__getattribute__(self, propname) except AttributeError: try: - return object.__getattribute__(self, propname) + return object.__getattribute__(dbobj, propname) except AttributeError: try: if FULL_PERSISTENCE and propname != 'ndb':