Source code for ferrosoft.apps.ferrobase.tables.table

#  Copyright (c) 2025 Ferrosoft GmbH. All rights reserved.
import django_tables2 as tables2


[docs] class Table(tables2.Table): """Base table class that adapts to the responsive UI and permission state. On render the table strips its ``fixed-layout`` CSS class in portrait/UI mode and removes the first visible column's link when the current user lacks ``UPDATE`` permission on the model. """
[docs] def before_render(self, request): """Apply responsive layout tweaks and permission-driven unlinkification. Args: request: The current HTTP request. ``None`` skips the responsive check; permission resolution still runs against the global permission registry. """ from ferrosoft.apps.ferrobase.views.generic import Permissions, Verb if ( request is not None and request.GET.get("ui", "") == "portrait" and "class" in self.attrs ): # Remove fixed-layout from class attribute, because it does not play nice in vertical UI layout. self.attrs["class"] = self.attrs["class"].replace("fixed-layout", "") # Usually the first column is linkified, pointing to model update page. # Check permission and unlinkify if necessary. first_col = next(self.columns.itervisible()) if ( first_col is not None and first_col.link is not None and not Permissions.allowed(request, self._meta.model, Verb.UPDATE) ): first_col.link = None