Adjusted the way typeclasses are searched. Should correctly find overloaded methods now.
This commit is contained in:
parent
2dd856d1f2
commit
d73dd65500
2 changed files with 16 additions and 17 deletions
|
|
@ -541,10 +541,10 @@ class TypedObject(SharedMemoryModel):
|
||||||
# typeclass' __getattribute__, since that one would
|
# typeclass' __getattribute__, since that one would
|
||||||
# try to look back to this very database object.)
|
# try to look back to this very database object.)
|
||||||
typeclass = object.__getattribute__(self, 'typeclass')
|
typeclass = object.__getattribute__(self, 'typeclass')
|
||||||
#print " '%s' not on db --> Checking typeclass %s instead." % (propname, typeclass)
|
|
||||||
if typeclass:
|
if typeclass:
|
||||||
return object.__getattribute__(typeclass(self), propname)
|
return object.__getattribute__(typeclass(self), propname)
|
||||||
raise
|
else:
|
||||||
|
raise AttributeError
|
||||||
|
|
||||||
#@property
|
#@property
|
||||||
def dbref_get(self):
|
def dbref_get(self):
|
||||||
|
|
@ -595,15 +595,16 @@ class TypedObject(SharedMemoryModel):
|
||||||
if not path:
|
if not path:
|
||||||
# this means we should get the default obj
|
# this means we should get the default obj
|
||||||
# without giving errors.
|
# without giving errors.
|
||||||
defpath = self.default_typeclass_path
|
defpath = object.__getattribute__(self, 'default_typeclass_path')
|
||||||
typeclass = self._path_import(defpath)
|
typeclass = object.__getattribute__(self, '_path_import')(defpath)
|
||||||
|
#typeclass = self._path_import(defpath)
|
||||||
else:
|
else:
|
||||||
typeclass = TYPECLASS_CACHE.get(path, None)
|
typeclass = TYPECLASS_CACHE.get(path, None)
|
||||||
if typeclass:
|
if typeclass:
|
||||||
# we've imported this before. We're done.
|
# we've imported this before. We're done.
|
||||||
return typeclass
|
return typeclass
|
||||||
# not in cache. Import anew.
|
# not in cache. Import anew.
|
||||||
typeclass = self._path_import(path)
|
typeclass = object.__getattribute__(self, "_path_import")(path)
|
||||||
if not callable(typeclass):
|
if not callable(typeclass):
|
||||||
# given path failed to import, fallback to default.
|
# given path failed to import, fallback to default.
|
||||||
errstring = " %s" % typeclass # this is an error message
|
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 += "\nThis seems to be just the path to a module. You need"
|
||||||
errstring += " to specify the actual typeclass name inside the module too."
|
errstring += " to specify the actual typeclass name inside the module too."
|
||||||
errstring += "\n Typeclass '%s' failed to load." % path
|
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
|
errstring += " Using Default class '%s'." % defpath
|
||||||
self.db_typeclass_path = defpath
|
self.db_typeclass_path = defpath
|
||||||
self.save()
|
self.save()
|
||||||
logger.log_errmsg(errstring)
|
logger.log_errmsg(errstring)
|
||||||
typeclass = self._path_import(defpath)
|
typeclass = object.__getattribute__(self, "_path_import")(defpath)
|
||||||
errmsg(errstring)
|
errmsg(errstring)
|
||||||
if not callable(typeclass):
|
if not callable(typeclass):
|
||||||
# if typeclass still doesn't exist, we're in trouble.
|
# if typeclass still doesn't exist, we're in trouble.
|
||||||
|
|
@ -628,7 +629,7 @@ class TypedObject(SharedMemoryModel):
|
||||||
self.db_typeclass_path = defpath
|
self.db_typeclass_path = defpath
|
||||||
self.save()
|
self.save()
|
||||||
logger.log_errmsg(errstring)
|
logger.log_errmsg(errstring)
|
||||||
typeclass = self._path_import(defpath)
|
typeclass = object.__getattribute__(self, "_path_import")(defpath)
|
||||||
errmsg(errstring)
|
errmsg(errstring)
|
||||||
else:
|
else:
|
||||||
TYPECLASS_CACHE[path] = typeclass
|
TYPECLASS_CACHE[path] = typeclass
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ from django.conf import settings
|
||||||
|
|
||||||
# To ensure the sanity of the model, there are a
|
# To ensure the sanity of the model, there are a
|
||||||
# few property names we won't allow the admin to
|
# 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
|
# to *in-game* safety (if you can edit typeclasses you have
|
||||||
# full access anyway), so no protection against changing
|
# full access anyway), so no protection against changing
|
||||||
# e.g. 'locks' or 'permissions' should go here.
|
# e.g. 'locks' or 'permissions' should go here.
|
||||||
|
|
@ -88,9 +88,9 @@ class TypeClass(object):
|
||||||
cls = object.__getattribute__(self, '__class__')
|
cls = object.__getattribute__(self, '__class__')
|
||||||
db_typeclass_path = "%s.%s" % (object.__getattribute__(cls, '__module__'),
|
db_typeclass_path = "%s.%s" % (object.__getattribute__(cls, '__module__'),
|
||||||
object.__getattribute__(cls, '__name__'))
|
object.__getattribute__(cls, '__name__'))
|
||||||
if not dbobj.db_typeclass_path == db_typeclass_path:
|
if not object.__getattribute__(dbobj, "db_typeclass_path") == db_typeclass_path:
|
||||||
dbobj.db_typeclass_path = db_typeclass_path
|
object.__setattr__(dbobj, "db_typeclass_path", db_typeclass_path)
|
||||||
dbobj.save()
|
object.__getattribute__(dbobj, "save")()
|
||||||
|
|
||||||
# (The inheriting typed object classes often extend this __init__ to
|
# (The inheriting typed object classes often extend this __init__ to
|
||||||
# add handlers etc.)
|
# add handlers etc.)
|
||||||
|
|
@ -118,12 +118,10 @@ class TypeClass(object):
|
||||||
return object.__getattribute__(self, propname)
|
return object.__getattribute__(self, propname)
|
||||||
#print "get %s (dbobj:%s)" % (propname, type(dbobj))
|
#print "get %s (dbobj:%s)" % (propname, type(dbobj))
|
||||||
try:
|
try:
|
||||||
#print "Typeclass: looking for %s on dbobj %s" % (propname, dbobj)
|
return object.__getattribute__(self, propname)
|
||||||
#print " <-- dbobj"
|
|
||||||
return object.__getattribute__(dbobj, propname)
|
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
try:
|
try:
|
||||||
return object.__getattribute__(self, propname)
|
return object.__getattribute__(dbobj, propname)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
try:
|
try:
|
||||||
if FULL_PERSISTENCE and propname != 'ndb':
|
if FULL_PERSISTENCE and propname != 'ndb':
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue