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)
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 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") amount = Column("Betrag", formatter="table.coloredFormatter")
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 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 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 BuildingLevelRoomTable(BootstrapTable): class Meta: table_args = { 'data-sort-name': 'room', 'data-query-params': 'perhaps_all_users_query_params', } room = LinkColumn("Raum") inhabitants = MultiBtnColumn('Bewohner') @property def toolbar(self): return button_toolbar("Display all users", href="#", id="rooms-toggle-all-users", icon="glyphicon-user")
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 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 SiteTable(BootstrapTable): site = LinkColumn("Site") buildings = MultiBtnColumn("Buildings")
class RoomOvercrowdedTable(BootstrapTable): room = LinkColumn("Raum") inhabitants = MultiBtnColumn("Bewohner") class Meta: table_args = {'data-sort-name': 'room'}
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', } 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( set([('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 = Column("Wert", formatter='table.coloredFormatter', 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="glyphicon-stats") @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>"