From 5874505902bf84511d95cb277f2773ccc8a7db4f Mon Sep 17 00:00:00 2001 From: Griatch Date: Wed, 10 Apr 2013 22:33:32 +0200 Subject: [PATCH] Changed object.player to return a typeclass. Resolves Issue 325. Also made sure that .typeclass always returns a typeclass, also if called on something which is already a typeclass. --- src/objects/models.py | 12 +++++++++--- src/typeclasses/typeclass.py | 7 ++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/objects/models.py b/src/objects/models.py index 6502f39b52..df475f596e 100644 --- a/src/objects/models.py +++ b/src/objects/models.py @@ -250,7 +250,13 @@ class ObjectDB(TypedObject): We have to be careful here since Player is also a TypedObject, so as to not create a loop. """ - return get_field_cache(self, "player") + player = get_field_cache(self, "player") + if player: + try: + return player.typeclass + except Exception,e: + print "player_get:", e + return player #@player.setter def __player_set(self, player): @@ -470,8 +476,8 @@ class ObjectDB(TypedObject): Retrieve sessions connected to this object. """ # if the player is not connected, this will simply be an empty list. - if _GA(self, "player"): - return _GA(_GA(self, "player"), "sessions") + if _GA(self, "db_player"): + return _GA(_GA(self, "db_player"), "get_all_sessions")() return [] sessions = property(__sessions_get) diff --git a/src/typeclasses/typeclass.py b/src/typeclasses/typeclass.py index 87c5c93075..eb29a595dd 100644 --- a/src/typeclasses/typeclass.py +++ b/src/typeclasses/typeclass.py @@ -81,8 +81,9 @@ class TypeClass(object): if not any('src.typeclasses.models.TypedObject' in str(mro) for mro in dbobj_mro): raise Exception("dbobj is not a TypedObject: %s: %s" % (dbobj_cls, dbobj_mro)) - # store the reference to the database model instance + # we should always be able to use dbobj/typeclass to get back an object of the desired type _SA(self, 'dbobj', dbobj) + _SA(self, 'typeclass', self) def __getattribute__(self, propname): """ @@ -95,10 +96,6 @@ class TypeClass(object): property on the class, it will NOT be accessible through getattr. """ - if propname == 'dbobj': - return _GA(self, 'dbobj') - if propname == 'typeclass': - return self if propname.startswith('__') and propname.endswith('__'): # python specials are parsed as-is (otherwise things like # isinstance() fail to identify the typeclass)