Moved db_player and db_sessid under metaclass wrappers.
This commit is contained in:
parent
fd9acd6bf9
commit
f11f330e95
3 changed files with 77 additions and 70 deletions
|
|
@ -155,74 +155,84 @@ class ObjectDB(TypedObject):
|
||||||
# value = self.attr and del self.attr respectively (where self
|
# value = self.attr and del self.attr respectively (where self
|
||||||
# is the object in question).
|
# is the object in question).
|
||||||
|
|
||||||
#TODO - make player-handler
|
|
||||||
# player property (wraps db_player)
|
|
||||||
#@property
|
|
||||||
def __player_get(self):
|
|
||||||
"""
|
|
||||||
Getter. Allows for value = self.player.
|
|
||||||
We have to be careful here since Player is also
|
|
||||||
a TypedObject, so as to not create a loop.
|
|
||||||
"""
|
|
||||||
player = _GA(self, "db_player")
|
|
||||||
#player = get_field_cache(self, "player")
|
|
||||||
if player:
|
|
||||||
try:
|
|
||||||
return player.typeclass
|
|
||||||
except Exception,e:
|
|
||||||
print "player_get:", e
|
|
||||||
return player
|
|
||||||
|
|
||||||
#@player.setter
|
## player property (wraps db_player)
|
||||||
def __player_set(self, player):
|
##@property
|
||||||
"Setter. Allows for self.player = value"
|
#def __player_get(self):
|
||||||
if inherits_from(player, TypeClass):
|
# """
|
||||||
player = player.dbobj
|
# Getter. Allows for value = self.player.
|
||||||
_SA(self, "db_player", player)
|
# We have to be careful here since Player is also
|
||||||
_GA(self, "save")()
|
# a TypedObject, so as to not create a loop.
|
||||||
#set_field_cache(self, "player", player)
|
# """
|
||||||
# we must set this here or superusers won't be able to
|
# player = _GA(self, "db_player")
|
||||||
# bypass lockchecks unless they start the game connected
|
# #player = get_field_cache(self, "player")
|
||||||
# to the character in question.
|
# if player:
|
||||||
self.locks.cache_lock_bypass(self)
|
# try:
|
||||||
|
# return player.typeclass
|
||||||
|
# except Exception,e:
|
||||||
|
# print "player_get:", e
|
||||||
|
# return player
|
||||||
|
|
||||||
#@player.deleter
|
##@player.setter
|
||||||
def __player_del(self):
|
#def __player_set(self, player):
|
||||||
"Deleter. Allows for del self.player"
|
# "Setter. Allows for self.player = value"
|
||||||
_SA(self, "db_player", None)
|
# if inherits_from(player, TypeClass):
|
||||||
_GA(self, "save")()
|
# player = player.dbobj
|
||||||
#del_field_cache(self, "player")
|
# _SA(self, "db_player", player)
|
||||||
player = property(__player_get, __player_set, __player_del)
|
# _GA(self, "save")()
|
||||||
|
# #set_field_cache(self, "player", player)
|
||||||
|
# # we must set this here or superusers won't be able to
|
||||||
|
# # bypass lockchecks unless they start the game connected
|
||||||
|
# # to the character in question.
|
||||||
|
# self.locks.cache_lock_bypass(self)
|
||||||
|
|
||||||
|
##@player.deleter
|
||||||
|
#def __player_del(self):
|
||||||
|
# "Deleter. Allows for del self.player"
|
||||||
|
# _SA(self, "db_player", None)
|
||||||
|
# _GA(self, "save")()
|
||||||
|
# #del_field_cache(self, "player")
|
||||||
|
#player = property(__player_get, __player_set, __player_del)
|
||||||
|
|
||||||
#sessid property (wraps db_sessid)
|
#sessid property (wraps db_sessid)
|
||||||
#@property
|
#@property
|
||||||
def __sessid_get(self):
|
#def __sessid_get(self):
|
||||||
|
# """
|
||||||
|
# Getter. Allows for value = self.sessid. Since sessid
|
||||||
|
# is directly related to self.player, we cannot have
|
||||||
|
# a sessid without a player being connected (but the
|
||||||
|
# opposite could be true).
|
||||||
|
# """
|
||||||
|
# return _GA(self, "db_sessid")
|
||||||
|
# #if not get_field_cache(self, "sessid"):
|
||||||
|
# # del_field_cache(self, "sessid")
|
||||||
|
# #return get_field_cache(self, "sessid")
|
||||||
|
##@sessid.setter
|
||||||
|
#def __sessid_set(self, sessid):
|
||||||
|
# "Setter. Allows for self.player = value"
|
||||||
|
# _SA(self, "db_sessid", sessid)
|
||||||
|
# _GA(self, "save")()
|
||||||
|
# #set_field_cache(self, "sessid", sessid)
|
||||||
|
##@sessid.deleter
|
||||||
|
#def __sessid_del(self):
|
||||||
|
# "Deleter. Allows for del self.player"
|
||||||
|
# _SA(self, "db_sessid", None)
|
||||||
|
# _GA(self, "save")()
|
||||||
|
# #del_field_cache(self, "sessid")
|
||||||
|
#sessid = property(__sessid_get, __sessid_set, __sessid_del)
|
||||||
|
|
||||||
|
def _at_db_player_save(self, new_value, old_value=None):
|
||||||
"""
|
"""
|
||||||
Getter. Allows for value = self.sessid. Since sessid
|
This is called automatically just before a new player is saved.
|
||||||
is directly related to self.player, we cannot have
|
|
||||||
a sessid without a player being connected (but the
|
|
||||||
opposite could be true).
|
|
||||||
"""
|
"""
|
||||||
return _GA(self, "db_sessid")
|
# we need to re-cache this for superusers to bypass.
|
||||||
#if not get_field_cache(self, "sessid"):
|
self.locks.cache_lock_bypass(self)
|
||||||
# del_field_cache(self, "sessid")
|
return new_value
|
||||||
#return get_field_cache(self, "sessid")
|
|
||||||
#@sessid.setter
|
|
||||||
def __sessid_set(self, sessid):
|
|
||||||
"Setter. Allows for self.player = value"
|
|
||||||
_SA(self, "db_sessid", sessid)
|
|
||||||
_GA(self, "save")()
|
|
||||||
#set_field_cache(self, "sessid", sessid)
|
|
||||||
#@sessid.deleter
|
|
||||||
def __sessid_del(self):
|
|
||||||
"Deleter. Allows for del self.player"
|
|
||||||
_SA(self, "db_sessid", None)
|
|
||||||
_GA(self, "save")()
|
|
||||||
#del_field_cache(self, "sessid")
|
|
||||||
sessid = property(__sessid_get, __sessid_set, __sessid_del)
|
|
||||||
|
|
||||||
def _at_db_location_save(self, new_value, old_value=None):
|
def _at_db_location_save(self, new_value, old_value=None):
|
||||||
"This is called automatically just before a new location is saved."
|
"""
|
||||||
|
This is called automatically just before a new location is saved.
|
||||||
|
"""
|
||||||
loc = new_value
|
loc = new_value
|
||||||
try:
|
try:
|
||||||
old_loc = old_value
|
old_loc = old_value
|
||||||
|
|
@ -394,24 +404,23 @@ class ObjectDB(TypedObject):
|
||||||
# del_field_cache(self, "destination")
|
# del_field_cache(self, "destination")
|
||||||
#destination = property(__destination_get, __destination_set, __destination_del)
|
#destination = property(__destination_get, __destination_set, __destination_del)
|
||||||
|
|
||||||
# cmdset_storage property.
|
# cmdset_storage property. We use a custom wrapper to manage this. This also
|
||||||
# This seems very sensitive to caching, so leaving it be for now. /Griatch
|
# seems very sensitive to caching, so leaving it be for now. /Griatch
|
||||||
#@property
|
#@property
|
||||||
def __cmdset_storage_get(self):
|
def __cmdset_storage_get(self):
|
||||||
"Getter. Allows for value = self.name. Returns a list of cmdset_storage."
|
"Getter. Allows for value = self.name. Returns a list of cmdset_storage."
|
||||||
if _GA(self, "db_cmdset_storage"):
|
storage = _GA(self, "db_cmdset_storage")
|
||||||
return [path.strip() for path in _GA(self, "db_cmdset_storage").split(',')]
|
# we need to check so storage is not None
|
||||||
return []
|
return [path.strip() for path in storage.split(',')] if storage else []
|
||||||
#@cmdset_storage.setter
|
#@cmdset_storage.setter
|
||||||
def __cmdset_storage_set(self, value):
|
def __cmdset_storage_set(self, value):
|
||||||
"Setter. Allows for self.name = value. Stores as a comma-separated string."
|
"Setter. Allows for self.name = value. Stores as a comma-separated string."
|
||||||
value = ",".join(str(val).strip() for val in make_iter(value))
|
_SA(self, "db_cmdset_storage", ",".join(str(val).strip() for val in make_iter(value)))
|
||||||
_SA(self, "db_cmdset_storage", value)
|
|
||||||
_GA(self, "save")()
|
_GA(self, "save")()
|
||||||
#@cmdset_storage.deleter
|
#@cmdset_storage.deleter
|
||||||
def __cmdset_storage_del(self):
|
def __cmdset_storage_del(self):
|
||||||
"Deleter. Allows for del self.name"
|
"Deleter. Allows for del self.name"
|
||||||
_SA(self, "db_cmdset_storage", "")
|
_SA(self, "db_cmdset_storage", None)
|
||||||
_GA(self, "save")()
|
_GA(self, "save")()
|
||||||
cmdset_storage = property(__cmdset_storage_get, __cmdset_storage_set, __cmdset_storage_del)
|
cmdset_storage = property(__cmdset_storage_get, __cmdset_storage_set, __cmdset_storage_del)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -194,7 +194,6 @@ class Attribute(SharedMemoryModel):
|
||||||
self.cached_value = value
|
self.cached_value = value
|
||||||
self.no_cache = False
|
self.no_cache = False
|
||||||
return self.cached_value
|
return self.cached_value
|
||||||
|
|
||||||
#@value.setter
|
#@value.setter
|
||||||
def __value_set(self, new_value):
|
def __value_set(self, new_value):
|
||||||
"""
|
"""
|
||||||
|
|
@ -205,12 +204,10 @@ class Attribute(SharedMemoryModel):
|
||||||
self.no_cache = False
|
self.no_cache = False
|
||||||
self.db_value = to_store
|
self.db_value = to_store
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._track_db_value_change.update(self.cached_value)
|
self._track_db_value_change.update(self.cached_value)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
#@value.deleter
|
#@value.deleter
|
||||||
def __value_del(self):
|
def __value_del(self):
|
||||||
"Deleter. Allows for del attr.value. This removes the entire attribute."
|
"Deleter. Allows for del attr.value. This removes the entire attribute."
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,7 @@ class SharedMemoryModelBase(ModelBase):
|
||||||
"Helper method to create property wrappers with unique names (must be in separate call)"
|
"Helper method to create property wrappers with unique names (must be in separate call)"
|
||||||
def _get(cls, fname):
|
def _get(cls, fname):
|
||||||
"Wrapper for getting database field"
|
"Wrapper for getting database field"
|
||||||
|
#print "_get:", fieldname, wrappername,_GA(cls,fieldname)
|
||||||
return _GA(cls, fieldname)
|
return _GA(cls, fieldname)
|
||||||
def _get_foreign(cls, fname):
|
def _get_foreign(cls, fname):
|
||||||
"Wrapper for returing foreignkey fields"
|
"Wrapper for returing foreignkey fields"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue