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


Python QueryExecuter.search_async方法代码示例

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


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

示例1: QueryEntryGadget

# 需要导入模块: from stoqlib.database.queryexecuter import QueryExecuter [as 别名]
# 或者: from stoqlib.database.queryexecuter.QueryExecuter import search_async [as 别名]

#.........这里部分代码省略.........
        self._popup.connect('create-item', self._on_popup__create_item)

    def _add_button(self, stock):
        image = gtk.image_new_from_stock(stock, gtk.ICON_SIZE_MENU)
        button = gtk.Button()
        button.set_relief(gtk.RELIEF_NONE)
        button.set_image(image)
        button.show()
        self.box.pack_start(button, False, False)
        return button

    def _replace_widget(self):
        # This will remove the entry, add a hbox in the entry old position, and
        # reattach the entry to this box. The box will then be used to add two
        # new buttons (one for searching, other for editing/adding new objects
        container = self.entry.parent

        # stolen from gazpacho code (widgets/base/base.py):
        props = {}
        for pspec in gtk.container_class_list_child_properties(container):
            props[pspec.name] = container.child_get_property(self.entry, pspec.name)

        self.box = gtk.HBox()
        self.box.show()
        self.entry.reparent(self.box)
        container.add(self.box)

        for name, value in props.items():
            container.child_set_property(self.box, name, value)

    def _find_items(self, text):
        self._filter.set_state(text)
        state = self._filter.get_state()
        return self._executer.search_async([state], limit=10)

    def _dispatch(self, value):
        self._source_id = None
        if self._last_operation is not None:
            self._last_operation.cancel()
        self._last_operation = self._find_items(value)
        self._last_operation.connect(
            'finish', lambda o: self._popup.add_items(o.get_result()))

    def _run_search(self):
        text = self.entry.get_text()
        if not text:
            return

        item = run_dialog(self.SEARCH_CLASS, self._parent, self.store,
                          double_click_confirm=True, initial_string=text)
        if item:
            self.set_value(self.get_object_from_item(item))

    def _run_editor(self, model=None, description=None):
        with api.new_store() as store:
            model = store.fetch(model)
            if self._on_run_editor is not None:
                retval = self._on_run_editor(store, model,
                                             description=description)
            else:
                rd = run_person_role_dialog if self._is_person else run_dialog
                retval = rd(self.ITEM_EDITOR, self._parent, store, model,
                            description=description)

        if store.committed:
            return self.store.fetch(retval)
开发者ID:leandrodax,项目名称:stoq,代码行数:70,代码来源:queryentry.py

示例2: QueryExecuterTest

# 需要导入模块: from stoqlib.database.queryexecuter import QueryExecuter [as 别名]
# 或者: from stoqlib.database.queryexecuter.QueryExecuter import search_async [as 别名]
class QueryExecuterTest(DomainTest):
    def setUp(self):
        DomainTest.setUp(self)
        self.qe = QueryExecuter(self.store)
        self.qe.set_search_spec(ClientCategory)
        self.sfilter = mock.Mock()
        self.qe.set_filter_columns(self.sfilter, ['name'])

    def _search_async(self, states):
        op = self.qe.search_async(states)
        self.qe._operation_executer._queue.join()
        return list(op.get_result())

    def _search_string_all(self, text):
        return self.qe.search([
            StringQueryState(filter=self.sfilter,
                             mode=StringQueryState.CONTAINS_ALL,
                             text=text)])

    def _search_string_all_async(self, text):
        return self._search_async([
            StringQueryState(filter=self.sfilter,
                             mode=StringQueryState.CONTAINS_ALL,
                             text=text)])

    def _search_string_exactly(self, text):
        return self.qe.search([
            StringQueryState(filter=self.sfilter,
                             mode=StringQueryState.CONTAINS_EXACTLY,
                             text=text)])

    def _search_string_exactly_async(self, text):
        return self._search_async([
            StringQueryState(filter=self.sfilter,
                             mode=StringQueryState.CONTAINS_EXACTLY,
                             text=text)])

    def _search_string_not(self, text):
        return self.qe.search([
            StringQueryState(filter=self.sfilter,
                             mode=StringQueryState.NOT_CONTAINS,
                             text=text)])

    def _search_string_not_async(self, text):
        return self._search_async([
            StringQueryState(filter=self.sfilter,
                             mode=StringQueryState.NOT_CONTAINS,
                             text=text)])

    def test_string_query(self):
        self.assertEquals(self.store.find(ClientCategory).count(), 0)
        self.create_client_category(u'EYE MOON FLARE 110 0.5')
        self.create_client_category(u'EYE MOON FLARE 120 1.0')
        self.create_client_category(u'EYE SUN FLARE 120 1.0')
        self.create_client_category(u'EYE SUN FLARE 110 1.0')
        self.create_client_category(u'EYE SUN STONE 120 0.5')

        self.assertEquals(self._search_string_all(u'eye flare 110').count(), 2)
        self.assertEquals(self._search_string_all(u'eye 0.5').count(), 2)
        self.assertEquals(self._search_string_all(u'eye 120').count(), 3)

        self.assertEquals(self._search_string_exactly(u'eye flare 110').count(), 0)
        self.assertEquals(self._search_string_exactly(u'eye 0.5').count(), 0)
        self.assertEquals(self._search_string_exactly(u'eye 120').count(), 0)

        self.assertEquals(self._search_string_not(u'stone 110').count(), 2)
        self.assertEquals(self._search_string_not(u'eye').count(), 0)
        self.assertEquals(self._search_string_not(u'moon 120').count(), 1)

    def test_search_async(self):
        self.assertEquals(self.store.find(ClientCategory).count(), 0)
        try:
            self.create_client_category(u'EYE MOON FLARE 110 0.5')
            self.create_client_category(u'EYE MOON FLARE 120 1.0')
            self.create_client_category(u'EYE SUN FLARE 120 1.0')
            self.create_client_category(u'EYE SUN FLARE 110 1.0')
            self.create_client_category(u'EYE SUN STONE 120 0.5')
            # search_async uses another connection. Because of that, we need to
            # commit the store or else it will not be able to find the objects
            self.store.commit()

            self.assertEquals(
                len(self._search_string_all_async(u'eye flare 110')), 2)
            self.assertEquals(
                len(self._search_string_all_async(u'eye 0.5')), 2)
            self.assertEquals(
                len(self._search_string_all_async(u'eye 120')), 3)

            self.assertEquals(
                len(self._search_string_exactly_async(u'eye flare 110')), 0)
            self.assertEquals(
                len(self._search_string_exactly_async(u'eye 0.5')), 0)
            self.assertEquals(
                len(self._search_string_exactly_async(u'eye 120')), 0)

            self.assertEquals(
                len(self._search_string_not_async(u'stone 110')), 2)
            self.assertEquals(
                len(self._search_string_not_async(u'eye')), 0)
            self.assertEquals(
#.........这里部分代码省略.........
开发者ID:Guillon88,项目名称:stoq,代码行数:103,代码来源:test_queryexecuter.py


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