本文整理匯總了Python中stoqlib.database.queryexecuter.QueryExecuter.set_query方法的典型用法代碼示例。如果您正苦於以下問題:Python QueryExecuter.set_query方法的具體用法?Python QueryExecuter.set_query怎麽用?Python QueryExecuter.set_query使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類stoqlib.database.queryexecuter.QueryExecuter
的用法示例。
在下文中一共展示了QueryExecuter.set_query方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TransactionPage
# 需要導入模塊: from stoqlib.database.queryexecuter import QueryExecuter [as 別名]
# 或者: from stoqlib.database.queryexecuter.QueryExecuter import set_query [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)
#.........這裏部分代碼省略.........