mirror of
https://github.com/evennia/evennia.git
synced 2026-03-26 09:46:32 +01:00
Made scripts and typeclassed objects remember db_typeclass_path at all times - a temporarily faulty typeclass will no longer mess up things forever after. Refined and optimized the way typeclasses are cached and loaded, minimizing db hits. The default result when trying to create an object or script with a typeclass that is faulty/not found is now to fail. The previous way, to create an entity anyway using defaults was hard to debug and caused confusion. Resolves issue 175.
This commit is contained in:
parent
6cb2b8b745
commit
ddfd8120bb
10 changed files with 208 additions and 173 deletions
|
|
@ -19,7 +19,7 @@ from django.conf import settings
|
|||
# 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.
|
||||
PROTECTED = ['id', 'dbobj', 'db', 'objects', 'typeclass',
|
||||
PROTECTED = ['id', 'dbobj', 'db', 'ndb', 'objects', 'typeclass',
|
||||
'attr', 'save', 'delete']
|
||||
|
||||
# If this is true, all non-protected property assignments
|
||||
|
|
@ -70,8 +70,8 @@ class TypeClass(object):
|
|||
o = dbobj.object_class(dbobj) : this is used when dbobj.object_class is already set.
|
||||
|
||||
"""
|
||||
# typecheck of dbobj - we can't allow it to be added here unless
|
||||
# unless it's really a TypedObject.
|
||||
# typecheck of dbobj - we can't allow it to be added here
|
||||
# unless it's really a TypedObject.
|
||||
dbobj_cls = object.__getattribute__(dbobj, '__class__')
|
||||
dbobj_mro = object.__getattribute__(dbobj_cls, '__mro__')
|
||||
if not any('src.typeclasses.models.TypedObject'
|
||||
|
|
@ -83,16 +83,13 @@ class TypeClass(object):
|
|||
# store the needed things on the typeclass
|
||||
object.__setattr__(self, '_protected_attrs', PROTECTED)
|
||||
|
||||
# sync the database object to this typeclass.
|
||||
cls = object.__getattribute__(self, '__class__')
|
||||
db_typeclass_path = "%s.%s" % (object.__getattribute__(cls, '__module__'),
|
||||
object.__getattribute__(cls, '__name__'))
|
||||
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.)
|
||||
# # sync the database object to this typeclass.
|
||||
# cls = object.__getattribute__(self, '__class__')
|
||||
# db_typeclass_path = "%s.%s" % (object.__getattribute__(cls, '__module__'),
|
||||
# object.__getattribute__(cls, '__name__'))
|
||||
# if not object.__getattribute__(dbobj, "db_typeclass_path") == db_typeclass_path:
|
||||
# object.__setattr__(dbobj, "db_typeclass_path", db_typeclass_path)
|
||||
# object.__getattribute__(dbobj, "save")()
|
||||
|
||||
def __getattribute__(self, propname):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue