class PurchaseViewer(gtk.Window): def __init__(self): gtk.Window.__init__(self) self.set_title('Purchases') self.search = SearchContainer(self.get_columns()) self.search.set_summary_label('price') self.add(self.search) self._setup_searching() self._create_filters() def _setup_searching(self): self.query = SQLObjectQueryExecuter() self.search.set_query_executer(self.query) self.query.set_table(Sale) def _create_filters(self): self.search.set_text_field_columns(['description']) self.search.add_filter(DateSearchFilter('Date:'), columns=['date']) def get_columns(self): return [Column('description', data_type=str, title='Description', expand=True), Column('price', data_type=currency, title='Price'), Column('date', data_type=datetime.date, width=90)]
class TaskViewer(gtk.Window): def __init__(self): gtk.Window.__init__(self) self.set_title('Tasks') self.search = SearchContainer(self.get_columns()) self.add(self.search) self._setup_searching() self._create_filters() def _setup_searching(self): self.query = SQLObjectQueryExecuter() self.query.set_query(self._executer_query) self.search.set_query_executer(self.query) self.query.set_table(Task) def _create_filters(self): categories = [(c.name, c.id) for c in Category.select()] categories.insert(0, ('Any', None)) self.category_filter = ComboSearchFilter( 'Category:', categories) self.search.add_filter( self.category_filter, SearchFilterPosition.TOP, ['categoryID']) self.search.set_text_field_columns(['title']) self.search.add_filter(DateSearchFilter('Date:'), columns=['date']) def _executer_query(self, query, conn): category_id = self.category_filter.get_state().value if category_id is not None: query = AND(Category.q.id == category_id, query) return Task.select(query) def get_columns(self): return [ Column('title', data_type=str, title='Title', expand=True), Column('category.name', title='Category'), Column('date', data_type=datetime.date, width=90) ]
def _setup_searching(self): self.query = SQLObjectQueryExecuter() self.search.set_query_executer(self.query) self.query.set_table(Sale)