def build_object(obj_key, caller=None): """ Build objects of a model. Args: obj_key: (string) The key of the object. caller: (command caller) If provide, running messages will send to the caller. """ # Get object's model name. model_name = OBJECT_KEY_HANDLER.get_model(obj_key) if not model_name: ostring = "Can not find the model of %s." % obj_key print(ostring) print(traceback.print_exc()) if caller: caller.msg(ostring) return try: # Get record. model_obj = get_model(settings.WORLD_DATA_APP, model_name) record = model_obj.objects.get(key=obj_key) except Exception, e: ostring = "Can not load record %s:%s %s" % (model_name, obj_key, e) print(ostring) print(traceback.print_exc()) if caller: caller.msg(ostring) return
def set_data_info(self, key): """ Set data_info's model and key. It puts info into attributes. Args: key: (string) Key of the data info. """ model = OBJECT_KEY_HANDLER.get_model(key) utils.set_obj_data_info(self, key, model) self.load_data() # initialize with data if self.db.FIRST_CREATE: self.set_initial_data() del self.db.FIRST_CREATE
def get_data_record(self): """ Get object's data record from database. """ # Get model and key names. key = self.get_info_key() if not key: return model = OBJECT_KEY_HANDLER.get_model(key) if not model: return # Get db model model_obj = get_model(settings.WORLD_DATA_APP, model) if not model_obj: raise MudderyError("%s can not open model %s" % (key, model)) # Get data record. try: data = model_obj.objects.get(key=key) except Exception, e: raise MudderyError("%s can not find key %s" % (key, key))
def build_object(obj_key, caller=None): """ Build objects of a model. Args: obj_key: (string) The key of the object. caller: (command caller) If provide, running messages will send to the caller. """ model_name = OBJECT_KEY_HANDLER.get_model(obj_key) if not model_name: ostring = "Can not find the model of %s." % obj_key print ostring print traceback.print_exc() return try: model_obj = get_model(settings.WORLD_DATA_APP, model_name) record = model_obj.objects.get(key=obj_key) except Exception, e: ostring = "Can not load record %s:%s %s" % (model_name, obj_key, e) print ostring print traceback.print_exc() return