def run(self, clear): if clear: clear_db() print(_('- db cleared')) model.load_db() print(_('- db loaded'))
class ArrowCSVGrid(Grid): session_on = True allowed_export_targets = {'csv': CSV} DateTimeColumn(_('Created'), ArrowRecord.created_utc, DateTimeFilter) def query_prep(self, query, has_sort, has_filters): # default sort if not has_sort: query = query.order_by(ArrowRecord.id) return query
class ArrowGrid(Grid): session_on = True DateTimeColumn(_('Created'), ArrowRecord.created_utc, DateTimeFilter) def query_prep(self, query, has_sort, has_filters): # default sort if not has_sort: query = query.order_by(ArrowRecord.id) return query
class CreateDB(Command): """ create the DB and fill with data, optionally clear first """ option_list = (Option('--clear', default=False, dest='clear', action="store_true", help=_('DROP all DB objects first')), ) def run(self, clear): if clear: clear_db() print(_('- db cleared')) model.load_db() print(_('- db loaded'))
Option('--clear', default=False, dest='clear', action="store_true", help=_('DROP all DB objects first')), ) def run(self, clear): if clear: clear_db() print(_('- db cleared')) model.load_db() print(_('- db loaded')) manager = Manager(create_app) manager.add_option('-c', dest='config', default='Dev', help=_('flask configuration to use'), required=False) manager.add_command('create-db', CreateDB()) @manager.command def list_routes(name='list-routes'): output = [] for rule in flask.current_app.url_map.iter_rules(): methods = ','.join(rule.methods) line = urllib.unquote("{:50s} {:20s} {}".format(rule.endpoint, methods, rule)) output.append(line) for line in sorted(output): print(line)
class DefaultOpGrid(Grid): session_on = True FirstNameColumn(_('First Name'), Person.firstname, TextFilter(Person.firstname, default_op=ops.eq))
class PeopleGrid(Grid): session_on = True FirstNameColumn(_('First Name'), Person.firstname, TextFilter) FullNameColumn(_('Full Name')) YesNoColumn(_('Active'), Person.inactive, reverse=True) EmailsColumn(_('Emails')) Column(_('Status'), Status.label.label('status'), StatusFilter(Status.id)) DateTimeColumn(_('Created'), Person.createdts, DateTimeFilter) DateColumn(_('Due Date'), 'due_date') Column(_('Sort Order'), Person.sortorder, render_in='xls') Column(_('State'), Person.state, render_in='xlsx') NumericColumn(_('Number'), Person.numericcol, has_subtotal=True) EnumColumn(_('Account Type'), Person.account_type, OptionsEnumFilter(Person.account_type, enum_type=AccountType)) def query_prep(self, query, has_sort, has_filters): query = query.add_columns( Person.id, Person.lastname, Person.due_date, Person.account_type, ).add_entity(Person).outerjoin(Person.status) # default sort if not has_sort: query = query.order_by(Person.id) return query
class StatusFilter(OptionsFilterBase): operators = (Operator('o', _('open'), None), ops.is_, ops.not_is, Operator('c', _('closed'), None), ops.empty, ops.not_empty) options_from = Status.pairs
def extract_data(self, record): return _('{record.firstname} {record.lastname}', record=record)
class PeopleGrid(PGBase): CurrencyCol(_('Currency'), Person.numericcol, format_as='percent', places=5) CurrencyCol(_('C2'), Person.numericcol.label('n2'), format_as='accounting')
help=_('DROP all DB objects first')), ) def run(self, clear): if clear: clear_db() print(_('- db cleared')) model.load_db() print(_('- db loaded')) manager = Manager(create_app) manager.add_option('-c', dest='config', default='Dev', help=_('flask configuration to use'), required=False) manager.add_command('create-db', CreateDB()) @manager.command def list_routes(name='list-routes'): output = [] for rule in flask.current_app.url_map.iter_rules(): methods = ','.join(rule.methods) line = urllib.unquote("{:50s} {:20s} {}".format( rule.endpoint, methods, rule)) output.append(line) for line in sorted(output): print(line)