def __init__(self, *a, **kw): super().__init__( *a, columns=[ # specific tables don't need the `type` Column('created_at', 'Erstellt um', width=2), Column('user', 'Nutzer', formatter='table.userFormatter'), Column('message', 'Nachricht'), ], **kw)
def __init__(self, *a, **kw): super().__init__(*a, columns=[ Column('created_at', 'Erstellt um', width=2), Column('type', 'Logtyp'), Column('user', 'Nutzer', formatter='table.userFormatter'), Column('message', 'Nachricht'), ], **kw)
def setUp(self): super().setUp() self.table = BootstrapTable(columns=[ Column(name="col1", title="Column 1"), Column(name="col2", title="Column 2") ], data_url="http://dummy", table_args={ 'foo': "bar", 'data-cache': "true" })
def __init__(self, *a, **kw): super().__init__(*a, columns=[ Column('ip', 'IP-Adresse'), Column('mac', 'Mac-Adresse'), Column('switch', 'Switch'), Column('port', 'Switchport'), Column('action', 'MAC ändern', formatter='table.btnFormatter') ], **kw)
def __init__(self, *a, user_id=None, **kw): super().__init__(*a, columns=[ Column('group_name', 'Gruppe'), Column('begins_at', 'Beginn'), Column('ends_at', 'Ende'), Column('actions', 'Aktionen', formatter='table.multiBtnFormatter') ], **kw) self.user_id = user_id
class SwitchTable(BootstrapTable): id = Column("#") name = LinkColumn("Name") ip = Column("Management IP") edit_link = BtnColumn('Editieren', width=1, hide_if=no_inf_change) delete_link = BtnColumn('Löschen', width=1, hide_if=no_inf_change) @property def toolbar(self): if not current_user.has_property('infrastructure_change'): return return button_toolbar("Switch", url_for(".switch_create"))
def __init__(self, *a, **kw): super().__init__(*a, columns=[ Column(name='user', title='Nutzer-ID', formatter='linkFormatter'), Column(name='valid_on', title='Gültig am'), Column(name='description', title='Beschreibung'), Column(name='amount', title='Betrag', formatter='coloredFormatter'), ], **kw)
class BankAccountTable(BootstrapTable): """A table for displaying bank accounts :param bool create_account: An optional switch adding a “create bank account” button to the toolbar """ name = Column("Name") bank = Column("Bank") ktonr = Column("Kontonummer") blz = Column("Bankleitzahl") iban = Column("IBAN") bic = Column("SWIFT-BIC") kto = BtnColumn("Konto") balance = Column("Saldo") last_imported_at = Column("Zuletzt importiert") def __init__(self, *a, create_account=False, **kw): self.create_account = create_account super().__init__(*a, **kw) @property def toolbar(self): """A “create bank account” button""" if not self.create_account: return href = url_for(".bank_accounts_create") return button_toolbar(gettext("Neues Bankkonto anlegen"), href)
class MembershipFeeTable(BootstrapTable): """A table for displaying the current membership fees""" name = Column("Name") regular_fee = Column("Regulär") payment_deadline = Column("Frist") payment_deadline_final = Column("Endgültige Frist") begins_on = DateColumn("Beginn") ends_on = DateColumn("Ende") actions = MultiBtnColumn("Aktionen") @property def toolbar(self): """An “add fee” button""" href = url_for(".membership_fee_create") return button_toolbar(gettext("Beitrag erstellen"), href)
class MembershipTable(BootstrapTable): """A table for displaying memberships In the toolbar, a “new membership” button is inserted if the :py:obj:`current_user` has the ``add_membership`` property. """ group_name = Column("Gruppe") begins_at = DateColumn("Beginn") ends_at = DateColumn("Ende") actions = MultiBtnColumn("Aktionen", hide_if=no_membership_change) def __init__(self, *a, user_id=None, **kw): super().__init__(*a, **kw) self.user_id = user_id @property def toolbar(self): if self.user_id is None: return if no_membership_change(): return href = url_for(".add_membership", user_id=self.user_id) return button_toolbar("Mitgliedschaft", href) class Meta: table_args = { 'data-row-attributes': 'table.membershipRowAttributes', 'data-row-style': 'table.membershipRowFormatter', 'class': 'membership-table' }
class BankAccountActivityTable(BootstrapTable): """A table for displaying bank account activities """ bank_account = Column("Bankkonto") name = Column("Name") valid_on = DateColumn("Gültig am") imported_at = DateColumn("Importiert am") reference = Column("Verwendungszweck") iban = Column("IBAN") amount = Column("Betrag") actions = MultiBtnColumn("Aktionen") class Meta: table_args = { 'data-sort-order': 'desc', 'data-sort-name': 'valid_on', }
class InterfaceTable(BootstrapTable): """A table for displaying interfaces """ name = Column("Name") mac = Column("MAC") ips = Column("IPs") actions = MultiBtnColumn("Aktionen", hide_if=no_hosts_change) def __init__(self, *a, host_id=None, **kw): table_args = kw.pop('table_args', {}) table_args.setdefault('data-hide-pagination-info', "true") table_args.setdefault('data-search', "false") kw['table_args'] = table_args super().__init__(*a, **kw) self.host_id = host_id
def test_instatiation_with_name_and_title_works(self): c = Column(title="Test Column", name="test_col") self.assertEqual(c.name, "test_col") self.assertEqual(c.title, "Test Column") self.assertEqual(c.width, 0) self.assertEqual(c.cell_style, False) self.assertEqual(repr(c), "<Column 'test_col' title='Test Column'>")
def test_custom_arguments_set(self): rendered = str( Column(title="Test Column", name="test_col", width=3, cell_style="customCellStyle")) self.assertIn('data-cell-style="customCellStyle"', rendered) self.assertIn('class="col-sm-3"', rendered)
class PortTable(BootstrapTable): def __init__(self, *a, switch_id=None, **kw): super().__init__(*a, **kw) self.switch_id = switch_id switchport_name = Column("Name", width=2) patchport_name = Column("→ Patchport", width=2) room = LinkColumn("→ Raum", width=10) edit_link = BtnColumn('Editieren', hide_if=no_inf_change) delete_link = BtnColumn('Löschen', hide_if=no_inf_change) @property def toolbar(self): if no_inf_change(): return href = url_for(".switch_port_create", switch_id=self.switch_id) return button_toolbar("Switch-Port", href)
class InstantiatedColumnTestCase(TestCase): def setUp(self): super().setUp() self.column = Column(title="Test Column", name="test_col") def test_col_args(self): arg_string = self.column.build_col_args() self.assertIn('data-field="test_col"', arg_string) self.assertIn('data-sortable="true"', arg_string) def test_col_render(self): rendered = str(self.column) self.assertEqual(self.column.render(), rendered) self.assertTrue(rendered.startswith("<th")) self.assertTrue(rendered.endswith("</th>")) self.assertIn(self.column.build_col_args(), rendered) self.assertIn(self.column.title, rendered)
class TransactionTable(BootstrapTable): """A table for displaying bank account activities """ account = LinkColumn("Konto") amount = Column("Wert") class Meta: table_args = { 'data-row-style': 'table.financeRowFormatter', }
def test_column_is_hidden(self): hide = False def hide_if(): return hide c = Column("Test", name='test_col', hide_if=hide_if) self.assertNotEqual(str(c), "") hide = True self.assertEqual(str(c), "", "Column rendered in spite of hide_if")
def __init__(self, *a, saldo=None, user_id=None, inverted=False, **kw): """Init :param int user_id: An optional user_id. If set, this causes a “details” button to be rendered in the toolbar referencing the user. :param bool inverted: An optional switch adding `style=inverted` to the given `data_url` """ table_args = { 'data-side-pagination': 'server', # 'data-search': 'true', 'data-sort-order': 'desc', 'data-sort-name': 'valid_on', } original_table_args = kw.pop('table_args', {}) table_args.update(original_table_args) if 'data_url' in kw and inverted: kw['data_url'] = enforce_url_params(kw['data_url'], params={'style': 'inverted'}) super().__init__(*a, columns=[ Column(name='posted_at', title='Erstellt um'), Column(name='valid_on', title='Gültig am'), Column(name='description', title='Beschreibung', formatter='table.linkFormatter'), Column(name='amount', title='Wert', formatter='table.coloredFormatter', cell_style='table.tdRelativeCellStyle'), ], table_args=table_args, **kw) if inverted: self.saldo = -saldo else: self.saldo = saldo self.user_id = user_id
class HostTable(BootstrapTable): """A table for displaying hosts """ name = Column("Name") switch = Column("Switch") port = Column("SwitchPort") actions = MultiBtnColumn("Aktionen", hide_if=no_hosts_change, width=3) interfaces_table_link = Column("", hide_if=lambda: True) interface_create_link = Column("", hide_if=lambda: True) id = Column("", hide_if=lambda: True) def __init__(self, *a, user_id=None, **kw): table_args = kw.pop('table_args', {}) table_args.setdefault('data-load-subtables', "true") table_args.setdefault('data-detail-view', "true") table_args.setdefault('data-detail-formatter', "table.hostDetailFormatter") table_args.setdefault('data-response-handler', "table.userHostResponseHandler") kw['table_args'] = table_args super().__init__(*a, **kw) self.user_id = user_id @property def toolbar(self): if self.user_id is None: return if no_hosts_change(): return href = url_for("host.host_create", user_id=self.user_id) return button_toolbar("Host", href)
class TaskTable(BootstrapTable): """A table for displaying tasks """ user = LinkColumn("User") name = Column("Name") due = DateColumn("Datum") creator = LinkColumn("Ersteller") status = Column("Status") actions = MultiBtnColumn("Aktionen", hide_if=no_membership_change) created = Column(title=None, hide_if=lambda: True) parameters = Column(title=None, hide_if=lambda: True) exception_message = Column(title=None, hide_if=lambda: True) type = Column("Typ", hide_if=lambda: True) def __init__(self, hidden_columns=[], *a, **kw): table_args = kw.pop('table_args', {}) table_args.setdefault('data-detail-view', "true") table_args.setdefault('data-sort-name', "due") table_args.setdefault('data-sort-order', "desc") table_args.setdefault('data-row-style', "table.taskRowFormatter") table_args.setdefault('data-detail-formatter', "table.taskDetailFormatter") if 'user' in hidden_columns: self.user.hide_if = lambda: True else: self.user.hide_if = lambda: False kw['table_args'] = table_args super().__init__(*a, **kw)
def __init__(self, *a, **kw): super().__init__(*a, columns=[ Column(name='name', title='Name'), Column(name='regular_fee', title='Regulär'), Column(name='payment_deadline', title='Frist'), Column(name='payment_deadline_final', title='Endgültige Frist'), Column(name='begins_on', title='Beginn'), Column(name='ends_on', title='Ende'), Column(name='finance_link', title='Finanzen', formatter='btnFormatter'), Column(name='book_link', title='Buchen', formatter='btnFormatter'), Column(name='edit_link', title='Bearbeiten', formatter='btnFormatter'), ], **kw)
class SubnetTable(BootstrapTable): id = Column("#") description = Column("Beschreibung") address = Column("IP") gateway = Column("Gateway") reserved = Column("Reservierte Adressen", formatter='table.listFormatter', sortable=False) free_ips_formatted = Column("Freie IPs", col_args={ 'data-sort-name': 'free_ips', })
class PatchPortTable(BootstrapTable): name = Column('Name', width=2) room = LinkColumn('→ Raum', width=5) switch_port = LinkColumn('→ Switch-Port', width=3) edit_link = BtnColumn('Editieren', hide_if=no_inf_change) delete_link = BtnColumn('Löschen', hide_if=no_inf_change) def __init__(self, *a, room_id=None, **kw): super().__init__(*a, **kw) self.room_id = room_id @property def toolbar(self): if no_inf_change(): return href = url_for(".patch_port_create", switch_room_id=self.room_id) return button_toolbar("Patch-Port", href)
class TrafficTopTable(BootstrapTable): """A table for displaying the users with the highest traffic usage""" url = LinkColumn("Name") traffic_for_days = Column("Traffic", formatter='table.byteFormatterBinary')
class SearchTable(BootstrapTable): """A table for displaying search results""" id = Column("ID") url = LinkColumn("Name") login = Column("Login")
class LogTableSpecific(RefreshableTableMixin, BootstrapTable): """A table for displaying logs""" created_at = DateColumn("Erstellt um", width=2) user = Column("Nutzer", formatter='table.userFormatter') message = Column("Nachricht")
class LogTableExtended(RefreshableTableMixin, BootstrapTable): """A table for displaying logs, with a ``type`` column""" created_at = DateColumn("Erstellt um", width=2) type_ = Column("Logtyp", name='type', sortable=False) user = Column("Nutzer", formatter='table.userFormatter') message = Column("Nachricht")
class Table(BootstrapTable): class Meta: table_args = {'foo': "bar", 'data-cache': "true"} col1 = Column("Column 1") col2 = Column("Column 2")
def test_init_requires_args(self): with self.assertRaises(TypeError): Column() # pylint: disable=no-value-for-parameter