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") iban = IbanColumn("IBAN") bic = Column("SWIFT-BIC") balance = Column("Saldo") last_imported_at = Column("Zuletzt importiert") kto = BtnColumn("Konto") 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 PortTable(BootstrapTable): class Meta: table_args = { 'data-sort-name': 'switchport_name', } def __init__(self, *a, switch_id=None, **kw): super().__init__(*a, **kw) self.switch_id = switch_id switchport_name = Column("Name", width=2, col_args={'data-sorter': 'table.sortPort'}) patchport_name = Column("→ Patchport", width=2, col_args={'data-sorter': 'table.sortPatchPort'}) 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 BankAccountActivityTable(BootstrapTable): """A table for displaying bank account activities """ bank_account = Column("Bankkonto", width=1) name = Column("Name", width=2) valid_on = DateColumn("Gültig am", width=1) imported_at = DateColumn("Importiert am", hide_if=lambda: True) reference = Column("Verwendungszweck") iban = Column("IBAN", hide_if=lambda: True) amount = Column("Betrag", width=1, formatter="table.euroFormatter") actions = MultiBtnColumn("Aktionen", width=1) def __init__(self, *a, **kw): table_args = kw.pop('table_args', {}) table_args.setdefault('data-detail-view', "true") table_args.setdefault('data-row-style', "table.financeRowFormatter") table_args.setdefault('data-detail-formatter', "table.bankAccountActivitiesDetailFormatter") kw['table_args'] = table_args super().__init__(*a, **kw) class Meta: table_args = { 'data-sort-order': 'desc', 'data-sort-name': 'valid_on', }
class UsersDueTable(BootstrapTable): """A table for displaying the users that """ user_id = Column("Nutzer-ID") user = LinkColumn("Name") valid_on = Column("Gültig am") description = Column("Beschreibung") fee_account_id = LinkColumn("Beitragskonto") amount = Column("Betrag", formatter="table.coloredFormatter")
class Table(BootstrapTable): a = Column("Column 1") b = Column("Column 2", name='bar') def toolbar(self): yield "<span>" yield "Hasta la vista, baby!" yield "</span>"
class UnconfirmedTransactionsTable(BootstrapTable): """A table for displaying unconfirmed transactions """ description = LinkColumn("Beschreibung") user = LinkColumn("Nutzer") room = Column("Wohnort") date = DateColumn("Datum") amount = Column("Wert") author = LinkColumn("Ersteller") actions = MultiBtnColumn("Aktionen")
class PreMemberTable(BootstrapTable): prm_id = Column("ID") name = TextWithBooleanColumn("Name") login = Column("Login") email = TextWithBooleanColumn("E-Mail Adresse") move_in_date = DateColumn("Einzug am") actions = MultiBtnColumn("Aktionen", hide_if=no_membership_change, width=1) class Meta: table_args = { 'data-row-style': 'table.membershipRequestRowFormatter', }
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"))
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' }
def test_instatiation_with_name_and_title_works(self): c = Column(title="Test Column", name="test_col") assert c.name == "test_col" assert c.title == "Test Column" assert c.width == 0 assert c.cell_style == False assert repr(c) == "<Column 'test_col' title='Test Column'>"
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
class PatchPortTable(BootstrapTable): class Meta: table_args = { 'data-sort-name': 'name', } name = Column('Name', width=2, col_args={'data-sorter': 'table.sortPatchPort'}) room = LinkColumn('→ Raum', width=5) switch_port = LinkColumn('→ Switch-Port', width=3, col_args={'data-sorter': 'table.sortPort'}) 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 ArchivableMembersTable(RefreshableTableMixin, BootstrapTable): class Meta: table_args = {'data-escape': 'false', 'data-sort-stable': True} id = Column("#") user = LinkColumn("Mitglied") room_shortname = LinkColumn("<i class=\"fas fa-home\"></i>") num_hosts = Column("<i class=\"fas fa-laptop\"></i>") current_properties = Column("Props", formatter="table.propertiesFormatter") end_of_membership = DateColumn("EOM") if typing.TYPE_CHECKING: @classmethod def row(cls, id: int, user: dict, room_shortname: dict, current_properties: str, num_hosts: int, end_of_membership: dict) -> dict: ...
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', }
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 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 RoomLogTable(BootstrapTable): created_at = DateColumn("Erstellt um") user = LinkColumn("Nutzer") message = Column("Nachricht")
class FinanceTable(BootstrapTable): class Meta: table_args = { 'data-side-pagination': 'server', # 'data-search': 'true', 'data-sort-order': 'desc', # 'data-sort-name': 'valid_on', 'data-page-list': '[5, 10, 25, 50, 100]' } 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` """ self.saldo = saldo if inverted: self._enforced_url_params = frozenset({ ('style', 'inverted') }.union(self._enforced_url_params)) self.saldo = -saldo super().__init__(*a, **kw) self.user_id = user_id self.table_footer_offset = 3 posted_at = Column("Erstellt um") valid_on = Column("Gültig am") description = LinkColumn("Beschreibung") amount = ColoredColumn("Wert", cell_style='table.tdRelativeCellStyle') @property def toolbar(self): """Generate a toolbar with a details button If a user_id was passed in the constructor, this renders a “details” button reaching the finance overview of the user's account. """ if self.user_id is None: return href = url_for("user.user_account", user_id=self.user_id) return button_toolbar("Details", href, icon="fa-chart-area") @property @lazy_join def table_footer(self): yield "<tfoot>" yield "<tr>" yield f"<td colspan=\"{self.table_footer_offset}\" class=\"text-right\">" yield "<strong>Saldo:</strong>" yield "</td>" yield "<td>" yield "{}".format( money_filter(self.saldo) if self.saldo is not None else "-") yield "</td>" yield "</tr>" yield "</tfoot>"
class ImportErrorTable(BootstrapTable): """A table for displaying buggy mt940 imports""" name = Column("Bankkonto") imported_at = Column("Importiert am") fix = BtnColumn("Importieren")
class B_(A): a = Column("Shizzle") c = Column("Baz")
def test_instantiation_without_name(self): c = Column("Test Title") assert c.name is None assert c.title == "Test Title"
def test_column_is_hidden(self): c = Column("Test", name='test_col', hide_if=lambda: True) assert str(c) == "", "Column rendered in spite of hide_if"
class Table(SplittedTable): splits = (('split1', "Split 1"), ('split2', "Split 2")) foo = Column("Foo") bar = Column("Bar")
def test_column_is_not_hidden(self): c = Column("Test", name='test_col', hide_if=lambda: False) assert str(c) != ""
def column(self): return Column(title="Test Column", name="test_col")
class VlanTable(BootstrapTable): id = Column("#") name = Column("Name") vid = Column("VID")
def rendered_col(self): return str( Column(title="Test Column", name="test_col", width=3, cell_style="customCellStyle"))
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 pytest.raises(TypeError): Column() # pylint: disable=no-value-for-parameter