当前位置: 首页>>代码示例>>Python>>正文


Python Pool.make_type_name方法代码示例

本文整理汇总了Python中trytond.pool.Pool.make_type_name方法的典型用法代码示例。如果您正苦于以下问题:Python Pool.make_type_name方法的具体用法?Python Pool.make_type_name怎么用?Python Pool.make_type_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在trytond.pool.Pool的用法示例。


在下文中一共展示了Pool.make_type_name方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update_index

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import make_type_name [as 别名]
    def update_index(cls, batch_size=100):
        """
        Update the remote elastic search index from the backlog and
        delete backlog entries once done.

        To be scalable, this operation limits itself to handling the oldest
        batch of records at a time. The batch_size can be optionally passed on
        to this function call. This should be small enough for subsequent
        transactions not to be blocked for a long time.

        That depends on your specific implementation and index size.
        """
        config = Pool().get('elasticsearch.configuration')(1)

        conn = config.get_es_connection()

        for item in cls.search_read(
                [], order=[('id', 'DESC')], limit=batch_size,
                fields_names=['record_model', 'record_id', 'id']):

            Model = Pool().get(item['record_model'])

            try:
                record, = Model.search([('id', '=', item['record_id'])])
            except ValueError:
                # Record may have been deleted
                try:
                    conn.delete(
                        config.index_name,                      # Index Name
                        config.make_type_name(Model.__name__),  # Document Type
                        item['record_id']
                    )
                except NotFoundException:
                    # This record was not there in elastic search too.
                    # Never mind!
                    pass
            else:
                if hasattr(record, 'elastic_search_json'):
                    # A model with the elastic_search_json method
                    data = record.elastic_search_json()
                else:
                    # A model without elastic_search_json
                    data = cls._build_default_doc(record)

                conn.index(
                    data,
                    config.index_name,                          # Index Name
                    config.make_type_name(record.__name__),     # Document Type
                    record.id,                                  # Record ID
                )
            finally:
                # Delete the item since it has been sent to the index
                cls.delete([cls(item['id'])])
开发者ID:PritishC,项目名称:trytond-elastic-search,代码行数:55,代码来源:index.py

示例2: _es_autocomplete

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import make_type_name [as 别名]
    def _es_autocomplete(cls, phrase):
        """
        Handler for auto-completion via elastic-search.
        The product's URL is generated here as request context is available
        here. This is sent to the front-end for typeaheadJS to compile into
        its suggestions template.
        """
        config = Pool().get('elasticsearch.configuration')(1)

        conn = config.get_es_connection(timeout=5)
        results = []

        search_obj = cls._quick_search_es(phrase, autocomplete=True)

        # Return the top 5 results as a list of dictionaries
        for product in conn.search(
            search_obj,
            doc_types=[config.make_type_name('product.product')],
            size=5
        ):
            display_name = product.name
            if product.code:
                display_name = '%s - %s' % (product.code, display_name)
            results.append(
                {
                    "id": product.id,
                    "type": product.type,
                    "display_name": display_name,
                    "url": cls(product.id).get_absolute_url(
                        _external=True
                    ),
                }
            )

        return results
开发者ID:fulfilio,项目名称:nereid-webshop-elastic-search,代码行数:37,代码来源:product.py

示例3: update_mapping

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import make_type_name [as 别名]
    def update_mapping(cls, document_types):
        """
        Update the mapping on the server side
        """
        config = Pool().get('elasticsearch.configuration')(1)

        conn = config.get_es_connection()

        for document_type in document_types:
            conn.indices.put_mapping(
                config.make_type_name(document_type.model.model),   # Type
                json.loads(document_type.mapping),                  # Mapping
                [config.index_name],                                # Index
            )
开发者ID:PritishC,项目名称:trytond-elastic-search,代码行数:16,代码来源:index.py

示例4: result_set

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import make_type_name [as 别名]
    def result_set(self):
        """
        Generates the `~pyes.es.ResultSet` object after performing the search.
        """
        config = Pool().get('elasticsearch.configuration')(1)

        conn = config.get_es_connection(timeout=5)

        return conn.search(
            self.search_obj,
            start=self.offset,
            size=self.per_page,
            doc_types=[config.make_type_name(self.model_name)]
        )
开发者ID:mbehrle,项目名称:nereid-webshop-elastic-search,代码行数:16,代码来源:pagination.py

示例5: all_items

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import make_type_name [as 别名]
    def all_items(self):
        """
        Returns all items.
        """
        config = Pool().get('elasticsearch.configuration')(1)

        conn = config.get_es_connection(timeout=5)

        return self.model.browse(
            map(
                lambda p: p.id, conn.search(
                    self.search_obj,
                    doc_types=[
                        config.make_type_name(self.model_name)
                    ]
                )
            )
        )
开发者ID:mbehrle,项目名称:nereid-webshop-elastic-search,代码行数:20,代码来源:pagination.py


注:本文中的trytond.pool.Pool.make_type_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。