本文整理汇总了Python中stoqlib.database.queryexecuter.QueryExecuter.set_table方法的典型用法代码示例。如果您正苦于以下问题:Python QueryExecuter.set_table方法的具体用法?Python QueryExecuter.set_table怎么用?Python QueryExecuter.set_table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stoqlib.database.queryexecuter.QueryExecuter
的用法示例。
在下文中一共展示了QueryExecuter.set_table方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _date_query
# 需要导入模块: from stoqlib.database.queryexecuter import QueryExecuter [as 别名]
# 或者: from stoqlib.database.queryexecuter.QueryExecuter import set_table [as 别名]
def _date_query(self, search_table, column):
sfilter = object()
executer = QueryExecuter(self.store)
executer.set_filter_columns(sfilter, [column])
executer.set_table(search_table)
state = DateIntervalQueryState(filter=sfilter,
start=self.start,
end=self.end)
return executer.search([state])
示例2: _setup_slaves
# 需要导入模块: from stoqlib.database.queryexecuter import QueryExecuter [as 别名]
# 或者: from stoqlib.database.queryexecuter.QueryExecuter import set_table [as 别名]
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)
示例3: _date_filter_query
# 需要导入模块: from stoqlib.database.queryexecuter import QueryExecuter [as 别名]
# 或者: from stoqlib.database.queryexecuter.QueryExecuter import set_table [as 别名]
def _date_filter_query(self, search_table, column):
executer = QueryExecuter(self.store)
executer.set_filter_columns(self.date_filter, [column])
executer.set_table(search_table)
return executer.search([self.date_filter.get_state()])
示例4: TransactionPage
# 需要导入模块: from stoqlib.database.queryexecuter import QueryExecuter [as 别名]
# 或者: from stoqlib.database.queryexecuter.QueryExecuter import set_table [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)
#.........这里部分代码省略.........
示例5: LoanSelectionStep
# 需要导入模块: from stoqlib.database.queryexecuter import QueryExecuter [as 别名]
# 或者: from stoqlib.database.queryexecuter.QueryExecuter import set_table [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()
示例6: SearchDialog
# 需要导入模块: from stoqlib.database.queryexecuter import QueryExecuter [as 别名]
# 或者: from stoqlib.database.queryexecuter.QueryExecuter import set_table [as 别名]
class SearchDialog(BasicDialog):
""" Base class for *all* the search dialogs, responsible for the list
construction and "Filter" and "Clear" buttons management.
This class must be subclassed and its subclass *must* implement the methods
'get_columns' and 'get_query_and_args' (if desired, 'get_query_and_args'
can be implemented in the user's slave class, so SearchDialog will get its
slave instance and call the method directly). Its subclass also must
implement a setup_slaves method and call its equivalent base class method
as in:
>>> def setup_slave(self):
... SearchDialog.setup_slaves(self)
or then, call it in its constructor, like:
>>> def __init__(self, *args):
... SearchDialog.__init__(self)
"""
main_label_text = ''
#: Title that will appear in the window, for instance 'Product Search'
title = ''
# The table type which we will query on to get the objects.
search_table = None
#: The label that will be used for the main filter in this dialog
search_label = None
#: Selection mode to use (if its possible to select more than one row)
selection_mode = gtk.SELECTION_BROWSE
#: Default size for this dialog
size = ()
#: If the advanced search is enabled or disabled. When ``True`` we will
#: instrospect the columns returned by :meth:`get_columns`,and use those
#: that are subclasses of :class:`stoqlib.gui.columns.SearchColumn` to add
#: as options for the user to filter the results.
advanced_search = True
tree = False
def __init__(self, store, search_table=None, hide_footer=True,
title='', selection_mode=None, double_click_confirm=False):
"""
A base class for search dialog inheritance
:param store: a store
:param table:
:param search_table:
:param hide_footer:
:param title:
:param selection_mode:
:param double_click_confirm: If double click a item in the list should
automatically confirm
"""
self.store = store
self.search_table = search_table or self.search_table
if not self.search_table:
raise ValueError("%r needs a search table" % self)
self.selection_mode = self._setup_selection_mode(selection_mode)
self.summary_label = None
self.double_click_confirm = double_click_confirm
BasicDialog.__init__(self, hide_footer=hide_footer,
main_label_text=self.main_label_text,
title=title or self.title,
size=self.size)
self.executer = QueryExecuter(store)
# FIXME: Remove this limit, but we need to migrate all existing
# searches to use lazy lists first. That in turn require
# 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)
#.........这里部分代码省略.........