1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

#3087: Add InvetoryItemRole

This commit is contained in:
jeremystretch
2021-12-27 10:18:39 -05:00
parent 77dd684916
commit 04fb5e544d
22 changed files with 469 additions and 10 deletions

View File

@@ -2,8 +2,8 @@ import django_tables2 as tables
from django_tables2.utils import Accessor
from dcim.models import (
ConsolePort, ConsoleServerPort, Device, DeviceBay, DeviceRole, FrontPort, Interface, InventoryItem, ModuleBay,
Platform, PowerOutlet, PowerPort, RearPort, VirtualChassis,
ConsolePort, ConsoleServerPort, Device, DeviceBay, DeviceRole, FrontPort, Interface, InventoryItem,
InventoryItemRole, ModuleBay, Platform, PowerOutlet, PowerPort, RearPort, VirtualChassis,
)
from tenancy.tables import TenantColumn
from utilities.tables import (
@@ -33,6 +33,7 @@ __all__ = (
'DeviceTable',
'FrontPortTable',
'InterfaceTable',
'InventoryItemRoleTable',
'InventoryItemTable',
'ModuleBayTable',
'PlatformTable',
@@ -68,11 +69,11 @@ def get_interface_state_attribute(record):
else:
return "disabled"
#
# Device roles
#
class DeviceRoleTable(BaseTable):
pk = ToggleColumn()
name = tables.Column(
@@ -791,6 +792,30 @@ class InventoryItemTable(DeviceComponentTable):
default_columns = ('pk', 'name', 'device', 'label', 'manufacturer', 'part_id', 'serial', 'asset_tag')
class InventoryItemRoleTable(BaseTable):
pk = ToggleColumn()
name = tables.Column(
linkify=True
)
inventoryitem_count = LinkedCountColumn(
viewname='dcim:inventoryitem_list',
url_params={'role_id': 'pk'},
verbose_name='Items'
)
color = ColorColumn()
tags = TagColumn(
url_name='dcim:inventoryitemrole_list'
)
actions = ButtonsColumn(InventoryItemRole)
class Meta(BaseTable.Meta):
model = InventoryItemRole
fields = (
'pk', 'id', 'name', 'inventoryitem_count', 'color', 'description', 'slug', 'tags', 'actions',
)
default_columns = ('pk', 'name', 'inventoryitem_count', 'color', 'description', 'actions')
class DeviceInventoryItemTable(InventoryItemTable):
name = tables.TemplateColumn(
template_code='<a href="{{ record.get_absolute_url }}" style="padding-left: {{ record.level }}0px">'