feat: show tenant column in netbox-inventory asset list
The asset table of netbox-inventory gets a tenant column (registered if the plugin does not provide one) that is part of the default columns, placed right after the status. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
cf1cafb632
commit
f86306e686
5 files changed
+61
-3
No files matched your search
@@ -790,7 +790,9 @@ a tenant takes the tenant of the device, module, inventory item or rack it is
|
||||
assigned to when it is saved. This keeps the plugin's *assign*, *reassign* and
|
||||
*create hardware from asset* views working with mandatory tenancy, which save
|
||||
the asset without a tenant field. An asset that is in stock and has no
|
||||
assigned hardware still needs a tenant.
|
||||
assigned hardware still needs a tenant. The asset list shows a **Tenant**
|
||||
column next to the status by default; users with a saved table configuration
|
||||
can add it via *Configure Table*.
|
||||
|
||||
`tenant_required = False` disables the feature permanently and takes precedence
|
||||
over the UI setting.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from netbox.plugins import PluginConfig, get_plugin_config
|
||||
|
||||
__version__ = "0.26.2"
|
||||
__version__ = "0.27.0"
|
||||
|
||||
|
||||
class NetBoxUtilitiesConfig(PluginConfig):
|
||||
@@ -76,6 +76,10 @@ class NetBoxUtilitiesConfig(PluginConfig):
|
||||
from .netbox_export import install_netbox_export_rack_width_support
|
||||
|
||||
install_netbox_export_rack_width_support()
|
||||
if self.apps.is_installed("netbox_inventory"):
|
||||
from .inventory_assets import install_asset_tenant_column
|
||||
|
||||
install_asset_tenant_column()
|
||||
if get_plugin_config("netbox_utilities", "reorder_rack_bulk_save_enabled"):
|
||||
from .reorder_rack import install_reorder_rack_bulk_save
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import django_tables2 as tables
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
COLUMN_NAME = "tenant"
|
||||
|
||||
|
||||
def add_to_default_columns(table, column=COLUMN_NAME, after=("status", "asset_tag", "hardware_type")):
|
||||
"""Show the column by default (users without saved table preferences), next to the status."""
|
||||
defaults = [name for name in table.Meta.default_columns if name != column]
|
||||
for anchor in after:
|
||||
if anchor in defaults:
|
||||
defaults.insert(defaults.index(anchor) + 1, column)
|
||||
break
|
||||
else:
|
||||
defaults.append(column)
|
||||
table.Meta.default_columns = tuple(defaults)
|
||||
|
||||
|
||||
def install_asset_tenant_column():
|
||||
"""Show the tenant of every netbox-inventory asset in the asset list."""
|
||||
from netbox_inventory.tables import AssetTable
|
||||
|
||||
if COLUMN_NAME not in AssetTable.base_columns:
|
||||
from utilities.tables import register_table_column
|
||||
|
||||
register_table_column(tables.Column(linkify=True, verbose_name=_("Tenant")), COLUMN_NAME, AssetTable)
|
||||
add_to_default_columns(AssetTable)
|
||||
@@ -0,0 +1,25 @@
|
||||
from types import SimpleNamespace
|
||||
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from netbox_utilities.inventory_assets import add_to_default_columns
|
||||
|
||||
|
||||
def fake_table(*default_columns):
|
||||
return SimpleNamespace(Meta=SimpleNamespace(default_columns=default_columns))
|
||||
|
||||
|
||||
class AssetTenantColumnTest(SimpleTestCase):
|
||||
def test_tenant_is_shown_after_status(self):
|
||||
table = fake_table("pk", "id", "name", "asset_tag", "status", "hardware", "tags")
|
||||
|
||||
add_to_default_columns(table)
|
||||
|
||||
self.assertEqual(table.Meta.default_columns, ("pk", "id", "name", "asset_tag", "status", "tenant", "hardware", "tags"))
|
||||
|
||||
def test_tenant_is_not_duplicated_and_appended_without_anchor(self):
|
||||
table = fake_table("pk", "tenant", "name")
|
||||
|
||||
add_to_default_columns(table)
|
||||
|
||||
self.assertEqual(table.Meta.default_columns, ("pk", "name", "tenant"))
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "netbox-utilities"
|
||||
version = "0.26.2"
|
||||
version = "0.27.0"
|
||||
description = "Navigation, tenant utilities, connection VLANs, partial-width racks, disks, CPU & RAM, switch port export and bulk operations for NetBox 4.6/4.7"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.12"
|
||||
|
||||
Reference in new issue
Block a user