From 626e42145a31202ba9f5541046a5d129022411b0 Mon Sep 17 00:00:00 2001 From: Tobias Genannt Date: Fri, 16 May 2025 20:29:56 +0200 Subject: [PATCH 1/2] Fixes #17719: User setting table stripe --- netbox/netbox/preferences.py | 9 +++++++++ netbox/netbox/tables/tables.py | 2 ++ netbox/users/forms/model_forms.py | 1 + 3 files changed, 12 insertions(+) diff --git a/netbox/netbox/preferences.py b/netbox/netbox/preferences.py index 4fdb7e31fe7..ca575bb57b7 100644 --- a/netbox/netbox/preferences.py +++ b/netbox/netbox/preferences.py @@ -54,6 +54,15 @@ def get_page_lengths(): default='bottom', description=_('Where the paginator controls will be displayed relative to a table') ), + 'ui.table.rows.striped': UserPreference( + label=_('Striped table rows'), + choices=( + ('', _('Disabled')), + ('true', _('Enabled')), + ), + description=_('Show striped effect on table rows'), + default=False, + ), # Miscellaneous 'data_format': UserPreference( diff --git a/netbox/netbox/tables/tables.py b/netbox/netbox/tables/tables.py index 6f6b30af20a..efca8b48ecb 100644 --- a/netbox/netbox/tables/tables.py +++ b/netbox/netbox/tables/tables.py @@ -163,6 +163,8 @@ def configure(self, request): columns = userconfig.get(f"tables.{self.name}.columns") if ordering is None: ordering = userconfig.get(f"tables.{self.name}.ordering") + if userconfig.get("ui.table.rows.striped"): + self.attrs['class'] += ' table-striped' # Fall back to the default columns & ordering if columns is None and hasattr(settings, 'DEFAULT_USER_PREFERENCES'): diff --git a/netbox/users/forms/model_forms.py b/netbox/users/forms/model_forms.py index 42c3b15f0a2..9f73330a973 100644 --- a/netbox/users/forms/model_forms.py +++ b/netbox/users/forms/model_forms.py @@ -59,6 +59,7 @@ class UserConfigForm(forms.ModelForm, metaclass=UserConfigFormMetaclass): fieldsets = ( FieldSet( 'locale.language', 'pagination.per_page', 'pagination.placement', 'ui.htmx_navigation', + 'ui.table.rows.striped', name=_('User Interface') ), FieldSet('data_format', name=_('Miscellaneous')), From aa81d67d6e3045099c20bea02632e6c3e36d78b6 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 26 Jun 2025 11:45:10 -0400 Subject: [PATCH 2/2] Tweak user preference name --- netbox/netbox/preferences.py | 5 ++--- netbox/netbox/tables/tables.py | 2 +- netbox/users/forms/model_forms.py | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/netbox/netbox/preferences.py b/netbox/netbox/preferences.py index ca575bb57b7..31e99824e63 100644 --- a/netbox/netbox/preferences.py +++ b/netbox/netbox/preferences.py @@ -54,14 +54,13 @@ def get_page_lengths(): default='bottom', description=_('Where the paginator controls will be displayed relative to a table') ), - 'ui.table.rows.striped': UserPreference( + 'ui.tables.striping': UserPreference( label=_('Striped table rows'), choices=( ('', _('Disabled')), ('true', _('Enabled')), ), - description=_('Show striped effect on table rows'), - default=False, + description=_('Render table rows with alternating colors to increase readability'), ), # Miscellaneous diff --git a/netbox/netbox/tables/tables.py b/netbox/netbox/tables/tables.py index efca8b48ecb..4d0cc90d80e 100644 --- a/netbox/netbox/tables/tables.py +++ b/netbox/netbox/tables/tables.py @@ -163,7 +163,7 @@ def configure(self, request): columns = userconfig.get(f"tables.{self.name}.columns") if ordering is None: ordering = userconfig.get(f"tables.{self.name}.ordering") - if userconfig.get("ui.table.rows.striped"): + if userconfig.get("ui.tables.striping"): self.attrs['class'] += ' table-striped' # Fall back to the default columns & ordering diff --git a/netbox/users/forms/model_forms.py b/netbox/users/forms/model_forms.py index 9f73330a973..d8773feb435 100644 --- a/netbox/users/forms/model_forms.py +++ b/netbox/users/forms/model_forms.py @@ -59,7 +59,7 @@ class UserConfigForm(forms.ModelForm, metaclass=UserConfigFormMetaclass): fieldsets = ( FieldSet( 'locale.language', 'pagination.per_page', 'pagination.placement', 'ui.htmx_navigation', - 'ui.table.rows.striped', + 'ui.tables.striping', name=_('User Interface') ), FieldSet('data_format', name=_('Miscellaneous')),