mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
#8787: Fix toggling of PK table column
This commit is contained in:
@ -41,23 +41,20 @@ class BaseTable(tables.Table):
|
|||||||
if self.empty_text is None:
|
if self.empty_text is None:
|
||||||
self.empty_text = f"No {self._meta.model._meta.verbose_name_plural} found"
|
self.empty_text = f"No {self._meta.model._meta.verbose_name_plural} found"
|
||||||
|
|
||||||
# Hide non-default columns
|
# Determine the table columns to display by checking the following:
|
||||||
default_columns = [*getattr(self.Meta, 'default_columns', self.Meta.fields), *self.exempt_columns]
|
# 1. User's configuration for the table
|
||||||
for column in self.columns:
|
# 2. Meta.default_columns
|
||||||
if column.name not in default_columns:
|
# 3. Meta.fields
|
||||||
self.columns.hide(column.name)
|
selected_columns = None
|
||||||
|
|
||||||
# Apply custom column ordering for user
|
|
||||||
if user is not None and not isinstance(user, AnonymousUser):
|
if user is not None and not isinstance(user, AnonymousUser):
|
||||||
selected_columns = user.config.get(f"tables.{self.__class__.__name__}.columns")
|
selected_columns = user.config.get(f"tables.{self.__class__.__name__}.columns")
|
||||||
if selected_columns:
|
if not selected_columns:
|
||||||
|
selected_columns = getattr(self.Meta, 'default_columns', self.Meta.fields)
|
||||||
|
|
||||||
# Show only persistent or selected columns
|
# Hide non-selected columns which are not exempt
|
||||||
for name, column in self.columns.items():
|
for column in self.columns:
|
||||||
if name in [*self.exempt_columns, *selected_columns]:
|
if column.name not in [*selected_columns, *self.exempt_columns]:
|
||||||
self.columns.show(name)
|
self.columns.hide(column.name)
|
||||||
else:
|
|
||||||
self.columns.hide(name)
|
|
||||||
|
|
||||||
# Rearrange the sequence to list selected columns first, followed by all remaining columns
|
# Rearrange the sequence to list selected columns first, followed by all remaining columns
|
||||||
# TODO: There's probably a more clever way to accomplish this
|
# TODO: There's probably a more clever way to accomplish this
|
||||||
|
Reference in New Issue
Block a user