# Copyright (c) 2025 Ferrosoft GmbH. All rights reserved.
from django.urls import reverse
from ferrosoft.apps.ferrobase.models import (
User,
IdSequenceConfig,
Organization,
Tenant,
SubscriptionPlan,
StoredFile,
FeatureAssignment,
APIToken,
)
from ferrosoft.apps.ferrobase.tables import EmptyExpandColumn, NumberColumn
from ferrosoft.apps.ferrobase.tables.crud import CRUDTable
from ferrosoft.apps.ferrobase.tables.columns import Column
from ferrosoft.apps.ferrobase.tables.table import Table
from ferrosoft.decimal import zero
[docs]
class APITokenTable(Table):
"""Read-only listing of ``APIToken`` records (name, tenant, status, expiry)."""
[docs]
class FeatureAssignmentTable(CRUDTable):
"""CRUD table for ``FeatureAssignment``; renders ``0`` limits as an em-dash."""
empty = EmptyExpandColumn()
limit = NumberColumn(transform=lambda value: "—" if value == zero else value)
[docs]
def get_delete_action_url(self, *args, **kwargs) -> str | None:
"""Resolve the delete URL via the ``featureassignment_delete`` route."""
return reverse(
"ferrobase:featureassignment_delete", args=[kwargs.get("record").pk]
)
[docs]
class IDSequenceTable(Table):
"""Listing of ID-sequence configurations linkified on the ``name`` column."""
name = Column(linkify=True)
[docs]
class OrganizationTable(Table):
"""Listing of ``Organization`` records linkified on the ``name`` column."""
name = Column(linkify=True)
[docs]
class StoredFileTable(Table):
"""Listing of stored files linking each name to its update view."""
name = Column(
linkify=lambda record: reverse("ferrobase:storedfile_update", args=[record.pk])
)
[docs]
class SubscriptionPlanTable(Table):
"""Listing of subscription plans linkified on the ``name`` column."""
name = Column(linkify=True)
[docs]
class TenantTable(CRUDTable):
"""CRUD table for tenants nested under an organisation."""
empty = EmptyExpandColumn()
[docs]
def get_delete_action_url(self, *args, **kwargs) -> str | None:
"""Resolve the delete URL via the ``tenant_delete`` route."""
return reverse("ferrobase:tenant_delete", args=[kwargs.get("record").pk])
[docs]
class UserTable(Table):
"""Listing of users linkified on the ``username`` column."""
username = Column(linkify=True)