當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。