def add_to_index(obj_identifier, **kwargs): object_path, pk = utils.split_obj_identifier(obj_identifier) model_class = utils.get_model_class(object_path) instance = model_class.objects.get(pk=pk) index = site.get_index(model_class) index.backend.update(index, [instance])
def get_model_class(self, object_path): """Fetch the model's class in a standarized way.""" model_class = utils.get_model_class(object_path) if model_class is None: self.log.error("Could not load model from '%s'. Moving on..." % object_path) return None return model_class
def add_to_index(obj_identifier, **kwargs): object_path, pk = utils.split_obj_identifier(obj_identifier) model_class = utils.get_model_class(object_path) try: instance = model_class.objects.get(pk=pk) except model_class.DoesNotExist, exc: retries_remaining = add_to_index.max_retries - kwargs['task_retries'] logger.warn("Could not find %s with pk=%s, will retry %d more times", model_class.__name__, pk, retries_remaining) add_to_index.retry(exc=exc)
def delete_from_index(obj_identifier, **kwargs): object_path, pk = utils.split_obj_identifier(obj_identifier) model_class = utils.get_model_class(object_path) index = site.get_index(model_class) index.remove_object(obj_identifier)