本文整理汇总了Python中stoqlib.gui.search.searchslave.SearchSlave.set_query_executer方法的典型用法代码示例。如果您正苦于以下问题:Python SearchSlave.set_query_executer方法的具体用法?Python SearchSlave.set_query_executer怎么用?Python SearchSlave.set_query_executer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stoqlib.gui.search.searchslave.SearchSlave
的用法示例。
在下文中一共展示了SearchSlave.set_query_executer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TransactionPage
# 需要导入模块: from stoqlib.gui.search.searchslave import SearchSlave [as 别名]
# 或者: from stoqlib.gui.search.searchslave.SearchSlave import set_query_executer [as 别名]
class TransactionPage(object):
# shows either a list of:
# - transactions
# - payments
def __init__(self, model, app, parent):
self.model = model
self.app = app
self.parent_window = parent
self._block = False
self._create_search()
self._add_date_filter()
self._setup_search()
self.refresh()
def get_toplevel(self):
return self.parent_window
def _create_search(self):
self.search = SearchSlave(self._get_columns(self.model.kind))
self.search.connect('result-item-activated',
self._on_search__item_activated)
self.search.enable_advanced_search()
self.query = QueryExecuter(self.app.store)
self.search.set_query_executer(self.query)
self.search.set_result_view(FinancialSearchResults)
self.result_view = self.search.result_view
self.result_view.page = self
tree_view = self.search.result_view.get_treeview()
tree_view.set_rules_hint(True)
tree_view.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_BOTH)
def _add_date_filter(self):
self.date_filter = DateSearchFilter(_('Date:'))
self.date_filter.clear_options()
self.date_filter.add_option(Any, 0)
year = datetime.datetime.today().year
month_names = get_month_names()
for i, month in enumerate(month_names):
name = month_names[i]
option = type(name + 'Option', (MonthOption, ),
{'name': _(name),
'month': i + 1,
'year': year})
self.date_filter.add_option(option, i + 1)
self.date_filter.add_custom_options()
self.date_filter.mode.select_item_by_position(0)
self.search.add_filter(self.date_filter)
def _append_date_query(self, field):
date = self.date_filter.get_state()
queries = []
if isinstance(date, DateQueryState) and date.date is not None:
queries.append(Date(field) == date.date)
elif isinstance(date, DateIntervalQueryState):
queries.append(Date(field) >= date.start)
queries.append(Date(field) <= date.end)
return queries
def _payment_query(self, store):
queries = self._append_date_query(self.query.table.due_date)
if queries:
return store.find(self.query.table, And(*queries))
return store.find(self.query.table)
def _transaction_query(self, store):
queries = [Or(self.model.id == AccountTransaction.account_id,
self.model.id == AccountTransaction.source_account_id)]
queries.extend(self._append_date_query(AccountTransaction.date))
return store.find(AccountTransactionView, And(*queries))
def show(self):
self.search.show()
def _setup_search(self):
if self.model.kind == 'account':
self.query.set_table(AccountTransactionView)
self.search.set_text_field_columns(['description'])
self.query.set_query(self._transaction_query)
elif self.model.kind == 'payable':
self.search.set_text_field_columns(['description', 'supplier_name'])
self.query.set_table(OutPaymentView)
self.query.set_query(self._payment_query)
elif self.model.kind == 'receivable':
self.search.set_text_field_columns(['description', 'drawee'])
self.query.set_table(InPaymentView)
self.query.set_query(self._payment_query)
else:
raise TypeError("unknown model kind: %r" % (self.model.kind, ))
def refresh(self):
self.search.result_view.clear()
if self.model.kind == 'account':
transactions = AccountTransactionView.get_for_account(self.model, self.app.store)
self.append_transactions(transactions)
elif self.model.kind == 'payable':
self._populate_payable_payments(OutPaymentView)
#.........这里部分代码省略.........
示例2: QuoteGroupSelectionStep
# 需要导入模块: from stoqlib.gui.search.searchslave import SearchSlave [as 别名]
# 或者: from stoqlib.gui.search.searchslave.SearchSlave import set_query_executer [as 别名]
class QuoteGroupSelectionStep(BaseWizardStep):
gladefile = 'QuoteGroupSelectionStep'
def __init__(self, wizard, store):
self._next_step = None
BaseWizardStep.__init__(self, store, wizard)
self._setup_slaves()
def _setup_slaves(self):
self.search = SearchSlave(self._get_columns(),
restore_name=self.__class__.__name__)
self.attach_slave('search_group_holder', self.search)
executer = QueryExecuter(self.store)
executer.set_table(QuotationView)
self.search.set_query_executer(executer)
self.search.set_text_field_columns(['supplier_name'])
filter = self.search.get_primary_filter()
filter.set_label(_(u'Supplier:'))
self.search.focus_search_entry()
self.search.results.connect('selection-changed',
self._on_searchlist__selection_changed)
self.search.results.connect('row-activated',
self._on_searchlist__row_activated)
date_filter = DateSearchFilter(_('Date:'))
self.search.add_filter(date_filter, columns=['open_date', 'deadline'])
self.edit_button.set_sensitive(False)
self.remove_button.set_sensitive(False)
def _get_columns(self):
return [IdentifierColumn('identifier', title=_("Quote #"), sorted=True),
IdentifierColumn('group_identifier', title=_('Group #')),
Column('supplier_name', title=_('Supplier'), data_type=str,
width=300),
Column('open_date', title=_('Open date'),
data_type=datetime.date),
Column('deadline', title=_('Deadline'),
data_type=datetime.date)]
def _can_purchase(self, item):
return item.cost > currency(0) and item.quantity > Decimal(0)
def _can_order(self, quotation):
if quotation is None:
return False
for item in quotation.purchase.get_items():
if not self._can_purchase(item):
return False
return True
def _update_view(self):
selected = self.search.results.get_selected()
has_selected = selected is not None
self.edit_button.set_sensitive(has_selected)
self.remove_button.set_sensitive(has_selected)
self.wizard.refresh_next(self._can_order(selected))
def _run_quote_editor(self):
store = api.new_store()
selected = store.fetch(self.search.results.get_selected().purchase)
retval = run_dialog(QuoteFillingDialog, self.wizard, selected, store)
store.confirm(retval)
store.close()
self._update_view()
def _remove_quote(self):
q = self.search.results.get_selected().quotation
msg = _('Are you sure you want to remove "%s" ?') % q.get_description()
if not yesno(msg, gtk.RESPONSE_NO,
_("Remove quote"), _("Don't remove")):
return
store = api.new_store()
group = store.fetch(q.group)
quote = store.fetch(q)
group.remove_item(quote)
# there is no reason to keep the group if there's no more quotes
if group.get_items().count() == 0:
QuoteGroup.delete(group.id, store=store)
store.confirm(True)
store.close()
self.search.refresh()
#
# WizardStep hooks
#
def next_step(self):
self.search.save_columns()
selected = self.search.results.get_selected()
if selected is None:
return
return QuoteGroupItemsSelectionStep(self.wizard, self.store,
selected.group, self)
#.........这里部分代码省略.........
示例3: LoanSelectionStep
# 需要导入模块: from stoqlib.gui.search.searchslave import SearchSlave [as 别名]
# 或者: from stoqlib.gui.search.searchslave.SearchSlave import set_query_executer [as 别名]
class LoanSelectionStep(BaseWizardStep):
gladefile = 'HolderTemplate'
def __init__(self, wizard, store):
BaseWizardStep.__init__(self, store, wizard)
self.setup_slaves()
def _create_filters(self):
self.search.set_text_field_columns(['client_name'])
def _get_columns(self):
return [IdentifierColumn('identifier', sorted=True),
SearchColumn('responsible_name', title=_(u'Responsible'),
data_type=str, expand=True),
SearchColumn('client_name', title=_(u'Client'),
data_type=str, expand=True),
SearchColumn('open_date', title=_(u'Opened'),
data_type=datetime.date),
SearchColumn('expire_date', title=_(u'Expire'),
data_type=datetime.date),
Column('loaned', title=_(u'Loaned'),
data_type=Decimal),
]
def _refresh_next(self, value=None):
can_continue = False
selected_rows = self.search.results.get_selected_rows()
if selected_rows:
client = selected_rows[0].client_id
branch = selected_rows[0].branch_id
# Only loans that belong to the same client and are from the same
# branch can be closed together
can_continue = all(v.client_id == client and v.branch_id == branch
for v in selected_rows)
self.wizard.refresh_next(can_continue)
def get_extra_query(self, states):
return LoanView.status == Loan.STATUS_OPEN
def setup_slaves(self):
self.search = SearchSlave(self._get_columns(),
restore_name=self.__class__.__name__)
self.search.enable_advanced_search()
self.attach_slave('place_holder', self.search)
self.executer = QueryExecuter(self.store)
self.search.set_query_executer(self.executer)
self.executer.set_table(LoanView)
self.executer.add_query_callback(self.get_extra_query)
self._create_filters()
self.search.results.connect('selection-changed',
self._on_results_selection_changed)
self.search.results.set_selection_mode(gtk.SELECTION_MULTIPLE)
self.search.focus_search_entry()
#
# WizardStep
#
def has_previous_step(self):
return False
def post_init(self):
self.register_validate_function(self._refresh_next)
self.force_validation()
def next_step(self):
# FIXME: For some reason, the loan isn't in self.store
views = self.search.results.get_selected_rows()
self.wizard.models = [self.store.fetch(v.loan) for v in views]
return LoanItemSelectionStep(self.wizard, self, self.store,
self.wizard.models)
#
# Callbacks
#
def _on_results_selection_changed(self, widget, selection):
self._refresh_next()
示例4: SearchDialog
# 需要导入模块: from stoqlib.gui.search.searchslave import SearchSlave [as 别名]
# 或者: from stoqlib.gui.search.searchslave.SearchSlave import set_query_executer [as 别名]
#.........这里部分代码省略.........
# us to rewrite the queries in such a way that count(*)
# will work properly.
self.executer.set_limit(sysparam(self.store).MAX_SEARCH_RESULTS)
self.set_table(self.search_table)
self.enable_window_controls()
self.disable_ok()
self.set_ok_label(_('Se_lect Items'))
self._setup_search()
self._setup_details_slave()
self.create_filters()
self.setup_widgets()
if self.search_label:
self.set_searchbar_label(self.search_label)
def _setup_selection_mode(self, selection_mode):
# For consistency do not allow none or single, in other words,
# only allowed values are browse and multiple so we always will
# be able to use both the keyboard and the mouse to select items
# in the search list.
selection_mode = selection_mode or self.selection_mode
if (selection_mode != gtk.SELECTION_BROWSE and
selection_mode != gtk.SELECTION_MULTIPLE):
raise ValueError('Invalid selection mode %r' % selection_mode)
return selection_mode
def _setup_search(self):
self.search = SearchSlave(
self.get_columns(),
tree=self.tree,
restore_name=self.__class__.__name__,
)
self.search.set_query_executer(self.executer)
if self.advanced_search:
self.search.enable_advanced_search()
self.attach_slave('main', self.search)
self.header.hide()
self.results = self.search.result_view
self.results.set_selection_mode(self.selection_mode)
self.results.connect('cell-edited', self._on_results__cell_edited)
self.results.connect('selection-changed',
self._on_results__selection_changed)
self.results.connect('row-activated', self._on_results__row_activated)
def _setup_details_slave(self):
# FIXME: Gross hack
has_details_btn = hasattr(self, 'on_details_button_clicked')
has_print_btn = hasattr(self, 'on_print_button_clicked')
if not (has_details_btn or has_print_btn):
self._details_slave = None
return
self._details_slave = _SearchDialogDetailsSlave()
self.attach_slave('details_holder', self._details_slave)
if has_details_btn:
self._details_slave.connect("details",
self.on_details_button_clicked)
else:
self._details_slave.details_button.hide()
if has_print_btn:
self._details_slave.connect("print", self.on_print_button_clicked)
self.set_print_button_sensitive(False)
self.results.connect('has-rows', self._has_rows)
else:
self._details_slave.print_button.hide()