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


Python QueryExecuter.set_search_spec方法代码示例

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


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

示例1: _date_query

# 需要导入模块: from stoqlib.database.queryexecuter import QueryExecuter [as 别名]
# 或者: from stoqlib.database.queryexecuter.QueryExecuter import set_search_spec [as 别名]
 def _date_query(self, search_spec, column):
     sfilter = object()
     executer = QueryExecuter(self.store)
     executer.set_filter_columns(sfilter, [column])
     executer.set_search_spec(search_spec)
     state = DateIntervalQueryState(filter=sfilter, start=self.start, end=self.end)
     return executer.search([state])
开发者ID:amaurihamasu,项目名称:stoq,代码行数:9,代码来源:sintegragenerator.py

示例2: get_query_executer

# 需要导入模块: from stoqlib.database.queryexecuter import QueryExecuter [as 别名]
# 或者: from stoqlib.database.queryexecuter.QueryExecuter import set_search_spec [as 别名]
    def get_query_executer(self):
        """
        Fetchs the QueryExecuter for the SearchContainer

        :returns: a querty executer
        :rtype: a :class:`QueryExecuter` subclass
        """
        if self._query_executer is None:
            executer = QueryExecuter(self.store)
            if not self._lazy_search:
                executer.set_limit(sysparam.get_int('MAX_SEARCH_RESULTS'))
            if self._search_spec is not None:
                executer.set_search_spec(self._search_spec)
            self._query_executer = executer
        return self._query_executer
开发者ID:Guillon88,项目名称:stoq,代码行数:17,代码来源:searchslave.py

示例3: QueryExecuterTest

# 需要导入模块: from stoqlib.database.queryexecuter import QueryExecuter [as 别名]
# 或者: from stoqlib.database.queryexecuter.QueryExecuter import set_search_spec [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_string_all(self, text):
        return self.qe.search([
            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_not(self, text):
        return self.qe.search([
            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)
开发者ID:Joaldino,项目名称:stoq,代码行数:47,代码来源:test_queryexecuter.py

示例4: _date_filter_query

# 需要导入模块: from stoqlib.database.queryexecuter import QueryExecuter [as 别名]
# 或者: from stoqlib.database.queryexecuter.QueryExecuter import set_search_spec [as 别名]
 def _date_filter_query(self, search_spec, column):
     executer = QueryExecuter(self.store)
     executer.set_filter_columns(self.date_filter, [column])
     executer.set_search_spec(search_spec)
     return executer.search([self.date_filter.get_state()])
开发者ID:marianaanselmo,项目名称:stoq,代码行数:7,代码来源:financialreportdialog.py

示例5: QueryEntryGadget

# 需要导入模块: from stoqlib.database.queryexecuter import QueryExecuter [as 别名]
# 或者: from stoqlib.database.queryexecuter.QueryExecuter import set_search_spec [as 别名]
class QueryEntryGadget(object):
    """This gadget modifies a ProxyEntry to behave like a ProxyComboEntry.

    When instanciated, the gadget will remove the entry from the editor, add
    a gtk.HBox on its place, and re-attach the entry to the newly created
    hbox. This hbox will also have a button to add/edit a new object.

    There are a few advantages in using this instead of a combo:

    - There is no need to prefill the combo with all the options, which can
      be very slow depending on the number of objects.

    - This allows the user to use a better search mechanism, allowing him to
      filter using multiple keywords and even candidade keys (like a client
      document)
    """

    MIN_KEY_LENGTH = 1
    LOADING_ITEMS_TEXT = _("Loading items...")
    NEW_ITEM_TEXT = _("Create a new item with that name")
    NEW_ITEM_TOOLTIP = _("Create a new item")
    EDIT_ITEM_TOOLTIP = _("Edit the selected item")
    ITEM_EDITOR = None
    SEARCH_CLASS = None
    SEARCH_SPEC = None
    SEARCH_COLUMNS = None

    def __init__(self, entry, store, initial_value=None,
                 parent=None, run_editor=None):
        """
        :param entry: The entry that we should modify
        :param store: The store that will be used for database queries
        :param initial_value: Initial value for the entry
        :param parent: The parent that should be respected when running other
          dialogs
        """
        super(QueryEntryGadget, self).__init__()

        self._current_obj = None
        self._parent = parent
        self._on_run_editor = run_editor
        self.entry = entry
        self.entry.set_mode(ENTRY_MODE_DATA)
        self.store = store

        # The filter that will be used. This is not really in the interface.
        # We will just use it to perform the search.
        self._filter = StringSearchFilter('')
        self._executer = QueryExecuter(self.store)
        self._executer.set_search_spec(self.SEARCH_SPEC)
        self._executer.set_filter_columns(self._filter, self.SEARCH_COLUMNS)

        self._last_operation = None
        self._source_id = None
        self._is_person = issubclass(self.ITEM_EDITOR, BasePersonRoleEditor)

        self._setup()
        self.set_value(initial_value, force=True)

    #
    #  Public API
    #

    def set_value(self, obj, force=False):
        if not force and obj == self._current_obj:
            return

        obj = self.store.fetch(obj)
        if obj is not None:
            value = obj.get_description()
            self.entry.prefill([(value, obj)])
            self.update_edit_button(gtk.STOCK_INFO, self.EDIT_ITEM_TOOLTIP)
        else:
            value = ''
            self.entry.prefill([])
            self.update_edit_button(gtk.STOCK_NEW, self.NEW_ITEM_TOOLTIP)

        self._current_obj = obj
        self.entry.update(obj)
        self.entry.set_text(value)

    def set_editable(self, can_edit):
        self.edit_button.set_sensitive(can_edit)
        self.entry.set_property('editable', can_edit)

    def update_edit_button(self, stock, tooltip):
        image = gtk.image_new_from_stock(stock, gtk.ICON_SIZE_MENU)
        self.edit_button.set_image(image)
        self.edit_button.set_tooltip_text(tooltip)

    def get_object_from_item(self, item):
        return item

    def describe_item(self, item):
        raise NotImplementedError

    #
    #  Private
    #

#.........这里部分代码省略.........
开发者ID:leandrodax,项目名称:stoq,代码行数:103,代码来源:queryentry.py

示例6: SearchEntryGadget

# 需要导入模块: from stoqlib.database.queryexecuter import QueryExecuter [as 别名]
# 或者: from stoqlib.database.queryexecuter.QueryExecuter import set_search_spec [as 别名]
class SearchEntryGadget(object):
    find_tooltip = _('Search')
    edit_tooltip = _('Edit')
    new_tooltip = _('Create')

    def __init__(self, entry, store, model, model_property,
                 search_columns, search_class, parent):
        """
        This gadget modifies a ProxyEntry turning it into a replacement for
        ProxyComboEntry.

        When instanciated, the gadget will remove the entry from the editor, add
        a gtk.HBox on its place, and re-attach the entry to the newly created
        hbox. This hbox will also have two buttons: One for showing the related
        search dialog (or search editor), and another one to add/edit a new
        object.

        There are a few advantages in using this instead of a combo:

        - There is no need to prefill the combo with all the options, which can
          be very slow depending on the number of objects.
        - This allows the user to use a better search mechanism, allowing him to
          filter using multiple keywords and even candidade keys (like a client
          document)

        :param entry: The entry that we should modify
        :param store: The store that will be used for database queries
        :param model: The model that we are updating
        :param model_property: Property name of the model that should be updated
        :param search_columns: Columns that will be queried when the user
          activates the entry
        :param search_class: Class of the search editor/dialog that will be
          displayed when more than one object is found
        :param parent: The parent that should be respected when running other
          dialogs
        :param find_tooltip: the tooltip to use for the search button
        :param edit_tooltip: the tooltip to use for the edit button
        :param new_tooltip: the tooltip to use for the new button
        """
        self.store = store
        self._entry = entry
        self._model = model
        # TODO: Maybe this two variables shoulb be a list of properties of the
        # table instead of strings
        self._model_property = model_property
        self._search_columns = search_columns
        self._search_class = search_class
        self._parent = parent

        # TODO: Respect permission manager
        self._editor_class = search_class.editor_class

        # If the search is for a person, the editor is called with a special
        # function
        if issubclass(search_class, BasePersonSearch):
            self._is_person = True
        else:
            self._is_person = False

        self._setup_widgets()
        self._setup_callbacks()

    #
    #   Private API
    #

    def _setup_widgets(self):
        self._replace_widget()

        # Add the two buttons
        self.find_button = self._create_button(gtk.STOCK_FIND)
        self.edit_button = self._create_button(gtk.STOCK_NEW)
        can_edit = self._entry.get_editable() and self._entry.get_sensitive()
        self.find_button.set_sensitive(can_edit)

        self.find_button.set_tooltip_text(self.find_tooltip)
        self.edit_button.set_tooltip_text(self.new_tooltip)

        # the entry needs a completion to work in MODE_DATA
        self._completion = gtk.EntryCompletion()
        self._entry.set_completion(self._completion)
        self._entry.set_mode(ENTRY_MODE_DATA)

        initial_value = getattr(self._model, self._model_property)
        self.set_value(initial_value)

        # The filter that will be used. This is not really in the interface. We
        # will just use it to perform the search.
        self._filter = StringSearchFilter('')
        self._executer = QueryExecuter(self.store)
        self._executer.set_search_spec(self._search_class.search_spec)
        self._executer.set_filter_columns(self._filter, self._search_columns)

    def _create_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)
#.........这里部分代码省略.........
开发者ID:barkinet,项目名称:stoq,代码行数:103,代码来源:searchentry.py

示例7: QueryExecuterTest

# 需要导入模块: from stoqlib.database.queryexecuter import QueryExecuter [as 别名]
# 或者: from stoqlib.database.queryexecuter.QueryExecuter import set_search_spec [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.set_search_spec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。