def remove(self, obj_or_string):
        """ accepts a haystack id such as APP_LABEL.MODEL.PK
            OR a model instance
        """
        if isinstance(obj_or_string, basestring):
            app_label, model_name, pk = obj_or_string.split('.')
            obj_id = u"%s__%s__%s" % (app_label, model_name, pk)
            index = get_model(app_label, model_name)
        else:
            obj_id = u"%s__%s__%s" % (obj_or_string._meta.app_label, obj_or_string._meta.module_name, obj_or_string._get_pk_value())
            index = self.get_index_for_obj(obj_or_string)

        doc_service = self.boto_conn.get_domain(self.get_searchdomain_name(index)).get_document_service()
        doc_service.delete(obj_id, gen_version())
        doc_service.commit()
Ejemplo n.º 2
0
    def remove(self, obj_or_string):
        """ accepts a haystack id such as APP_LABEL.MODEL.PK
            OR a model instance
        """
        if isinstance(obj_or_string, basestring):
            app_label, model_name, pk = obj_or_string.split('.')
            obj_id = u"%s__%s__%s" % (app_label, model_name, pk)
            index = get_model(app_label, model_name)
        else:
            obj_id = u"%s__%s__%s" % (obj_or_string._meta.app_label, obj_or_string._meta.module_name, obj_or_string._get_pk_value())
            index = self.get_index_for_obj(obj_or_string)

        doc_service = self.boto_conn.get_domain(self.get_searchdomain_name(index)).get_document_service()
        doc_service.delete(obj_id, gen_version())
        doc_service.commit()
        prepped_objs = []
        for obj in iterable:
            try:
                prepped_objs.append(index.full_prepare(obj))
            # we need to map which exceptions are possible here and handle them appropriately
            except Exception, e:
                if not self.silently_fail:
                    raise

                name = getattr(e, '__name__', e.__class__.__name__)
                self.log.error(u'%s while preparing object for update' % name, exc_info=True, extra={'data': {'index': index, 'object': get_identifier(obj)}})

        # this needs some help in terms of generating an id
        for obj in prepped_objs:
            obj['id'] = obj['id'].replace('.', '__')
            doc_service.add(obj['id'], gen_version(obj), obj)
        # this can fail if the upload is too large;
        # there should be some error handling around this
        doc_service.commit()

    def remove(self, obj_or_string):
        """ accepts a haystack id such as APP_LABEL.MODEL.PK
            OR a model instance
        """
        if isinstance(obj_or_string, basestring):
            app_label, model_name, pk = obj_or_string.split('.')
            obj_id = u"%s__%s__%s" % (app_label, model_name, pk)
            index = get_model(app_label, model_name)
        else:
            obj_id = u"%s__%s__%s" % (obj_or_string._meta.app_label, obj_or_string._meta.module_name, obj_or_string._get_pk_value())
            index = self.get_index_for_obj(obj_or_string)
Ejemplo n.º 4
0
        prepped_objs = []
        for obj in iterable:
            try:
                prepped_objs.append(index.full_prepare(obj))
            # we need to map which exceptions are possible here and handle them appropriately
            except Exception, e:
                if not self.silently_fail:
                    raise

                name = getattr(e, '__name__', e.__class__.__name__)
                self.log.error(u'%s while preparing object for update' % name, exc_info=True, extra={'data': {'index': index, 'object': get_identifier(obj)}})

        # this needs some help in terms of generating an id
        for obj in prepped_objs:
            obj['id'] = obj['id'].replace('.', '__')
            doc_service.add(obj['id'], gen_version(obj), obj)
        # this can fail if the upload is too large;
        # there should be some error handling around this
        doc_service.commit()

    def remove(self, obj_or_string):
        """ accepts a haystack id such as APP_LABEL.MODEL.PK
            OR a model instance
        """
        if isinstance(obj_or_string, basestring):
            app_label, model_name, pk = obj_or_string.split('.')
            obj_id = u"%s__%s__%s" % (app_label, model_name, pk)
            index = get_model(app_label, model_name)
        else:
            obj_id = u"%s__%s__%s" % (obj_or_string._meta.app_label, obj_or_string._meta.module_name, obj_or_string._get_pk_value())
            index = self.get_index_for_obj(obj_or_string)