Removes logging when associating a model to something that isn't a model class.
This commit is contained in:
@@ -184,21 +184,19 @@ class BasicModel(object):
|
|||||||
|
|
||||||
@absorb_connection_error
|
@absorb_connection_error
|
||||||
def add_to_index(self):
|
def add_to_index(self):
|
||||||
|
"""Each insance of Foo has its id tracked int the set named Foos"""
|
||||||
set_name = self.__class__._redis_set_name(self.__class__.__name__)
|
set_name = self.__class__._redis_set_name(self.__class__.__name__)
|
||||||
Redis.instance().sadd(set_name, self.identifier)
|
Redis.instance().sadd(set_name, self.identifier)
|
||||||
|
|
||||||
@absorb_connection_error
|
@absorb_connection_error
|
||||||
def remove_from_index(self):
|
def remove_from_index(self):
|
||||||
set_name = self.__class__._redis_set_name(self.__class__.__name__)
|
"""Remove id of this instance from the set tracking ids of this type"""
|
||||||
Redis.instance().srem(set_name, self.identifier)
|
|
||||||
|
|
||||||
@absorb_connection_error
|
|
||||||
def remove_from_index(self):
|
|
||||||
set_name = self.__class__._redis_set_name(self.__class__.__name__)
|
set_name = self.__class__._redis_set_name(self.__class__.__name__)
|
||||||
Redis.instance().srem(set_name, self.identifier)
|
Redis.instance().srem(set_name, self.identifier)
|
||||||
|
|
||||||
@absorb_connection_error
|
@absorb_connection_error
|
||||||
def associate_with(self, foreign_type, foreign_id):
|
def associate_with(self, foreign_type, foreign_id):
|
||||||
|
"""Add this class id into the set foreign_type:foreign_id:this_types"""
|
||||||
# note the extra 's' on the end is for plurality
|
# note the extra 's' on the end is for plurality
|
||||||
# to match the old data without requiring a migration of any sort
|
# to match the old data without requiring a migration of any sort
|
||||||
self.add_associated_model_to_its_set(foreign_type, foreign_id)
|
self.add_associated_model_to_its_set(foreign_type, foreign_id)
|
||||||
@@ -208,21 +206,24 @@ class BasicModel(object):
|
|||||||
|
|
||||||
@absorb_connection_error
|
@absorb_connection_error
|
||||||
def unassociate_with(self, foreign_type, foreign_id):
|
def unassociate_with(self, foreign_type, foreign_id):
|
||||||
|
"""Delete from foreign_type:foreign_id:this_types set"""
|
||||||
redis_set = self.__class__._redis_association_name(foreign_type,
|
redis_set = self.__class__._redis_association_name(foreign_type,
|
||||||
foreign_id)
|
foreign_id)
|
||||||
Redis.instance().srem(redis_set, self.identifier)
|
Redis.instance().srem(redis_set, self.identifier)
|
||||||
|
|
||||||
def add_associated_model_to_its_set(self, my_type, my_id):
|
def add_associated_model_to_its_set(self, model_type, model_id):
|
||||||
|
"""
|
||||||
|
When associating an X to a Y, save Y for newer timestamp, etc, and to
|
||||||
|
make sure to save it if Y is a new record.
|
||||||
|
If the model_type isn't found as a usable class, ignore it, this can
|
||||||
|
happen when associating to things stored in LDAP (user, project, ...).
|
||||||
|
"""
|
||||||
table = globals()
|
table = globals()
|
||||||
klsname = my_type.capitalize()
|
klsname = model_type.capitalize()
|
||||||
if table.has_key(klsname):
|
if table.has_key(klsname):
|
||||||
my_class = table[klsname]
|
model_class = table[klsname]
|
||||||
my_inst = my_class(my_id)
|
model_inst = model_class(model_id)
|
||||||
my_inst.save()
|
model_inst.save()
|
||||||
else:
|
|
||||||
logging.warning("no model class for %s when building"
|
|
||||||
" association from %s",
|
|
||||||
klsname, self)
|
|
||||||
|
|
||||||
@absorb_connection_error
|
@absorb_connection_error
|
||||||
def save(self):
|
def save(self):
|
||||||
|
Reference in New Issue
Block a user