Skip to content

Commit 2fe8df3

Browse files
authored
10655 fix contacts display in list views (#10681)
* 10655 fix contacts display in list views * 10655 review changes
1 parent 64d67e3 commit 2fe8df3

File tree

11 files changed

+78
-78
lines changed

11 files changed

+78
-78
lines changed

netbox/circuits/tables/circuits.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import django_tables2 as tables
2-
32
from circuits.models import *
3+
from tenancy.tables import ContactsColumnMixin, TenancyColumnsMixin
4+
45
from netbox.tables import NetBoxTable, columns
5-
from tenancy.tables import TenancyColumnsMixin
6+
67
from .columns import CommitRateColumn
78

89
__all__ = (
@@ -39,7 +40,7 @@ class Meta(NetBoxTable.Meta):
3940
default_columns = ('pk', 'name', 'circuit_count', 'description', 'slug')
4041

4142

42-
class CircuitTable(TenancyColumnsMixin, NetBoxTable):
43+
class CircuitTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
4344
cid = tables.Column(
4445
linkify=True,
4546
verbose_name='Circuit ID'
@@ -58,9 +59,6 @@ class CircuitTable(TenancyColumnsMixin, NetBoxTable):
5859
)
5960
commit_rate = CommitRateColumn()
6061
comments = columns.MarkdownColumn()
61-
contacts = columns.ManyToManyColumn(
62-
linkify_item=True
63-
)
6462
tags = columns.TagColumn(
6563
url_name='circuits:circuit_list'
6664
)

netbox/circuits/tables/providers.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import django_tables2 as tables
2+
from circuits.models import *
23
from django_tables2.utils import Accessor
4+
from tenancy.tables import ContactsColumnMixin
35

4-
from circuits.models import *
56
from netbox.tables import NetBoxTable, columns
67

78
__all__ = (
@@ -10,7 +11,7 @@
1011
)
1112

1213

13-
class ProviderTable(NetBoxTable):
14+
class ProviderTable(ContactsColumnMixin, NetBoxTable):
1415
name = tables.Column(
1516
linkify=True
1617
)
@@ -31,9 +32,6 @@ class ProviderTable(NetBoxTable):
3132
verbose_name='Circuits'
3233
)
3334
comments = columns.MarkdownColumn()
34-
contacts = columns.ManyToManyColumn(
35-
linkify_item=True
36-
)
3735
tags = columns.TagColumn(
3836
url_name='circuits:provider_list'
3937
)

netbox/dcim/tables/devices.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
import django_tables2 as tables
2-
from django_tables2.utils import Accessor
3-
42
from dcim.models import (
5-
ConsolePort, ConsoleServerPort, Device, DeviceBay, DeviceRole, FrontPort, Interface, InventoryItem,
6-
InventoryItemRole, ModuleBay, Platform, PowerOutlet, PowerPort, RearPort, VirtualChassis,
3+
ConsolePort,
4+
ConsoleServerPort,
5+
Device,
6+
DeviceBay,
7+
DeviceRole,
8+
FrontPort,
9+
Interface,
10+
InventoryItem,
11+
InventoryItemRole,
12+
ModuleBay,
13+
Platform,
14+
PowerOutlet,
15+
PowerPort,
16+
RearPort,
17+
VirtualChassis,
718
)
19+
from django_tables2.utils import Accessor
20+
from tenancy.tables import ContactsColumnMixin, TenancyColumnsMixin
21+
822
from netbox.tables import NetBoxTable, columns
9-
from tenancy.tables import TenancyColumnsMixin
23+
1024
from .template_code import *
1125

1226
__all__ = (
@@ -137,7 +151,7 @@ class Meta(NetBoxTable.Meta):
137151
# Devices
138152
#
139153

140-
class DeviceTable(TenancyColumnsMixin, NetBoxTable):
154+
class DeviceTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
141155
name = tables.TemplateColumn(
142156
order_by=('_name',),
143157
template_code=DEVICE_LINK
@@ -201,9 +215,6 @@ class DeviceTable(TenancyColumnsMixin, NetBoxTable):
201215
verbose_name='VC Priority'
202216
)
203217
comments = columns.MarkdownColumn()
204-
contacts = columns.ManyToManyColumn(
205-
linkify_item=True
206-
)
207218
tags = columns.TagColumn(
208219
url_name='dcim:device_list'
209220
)

netbox/dcim/tables/devicetypes.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
import django_tables2 as tables
2-
32
from dcim.models import (
4-
ConsolePortTemplate, ConsoleServerPortTemplate, DeviceBayTemplate, DeviceType, FrontPortTemplate, InterfaceTemplate,
5-
InventoryItemTemplate, Manufacturer, ModuleBayTemplate, PowerOutletTemplate, PowerPortTemplate, RearPortTemplate,
3+
ConsolePortTemplate,
4+
ConsoleServerPortTemplate,
5+
DeviceBayTemplate,
6+
DeviceType,
7+
FrontPortTemplate,
8+
InterfaceTemplate,
9+
InventoryItemTemplate,
10+
Manufacturer,
11+
ModuleBayTemplate,
12+
PowerOutletTemplate,
13+
PowerPortTemplate,
14+
RearPortTemplate,
615
)
16+
from tenancy.tables import ContactsColumnMixin
17+
718
from netbox.tables import NetBoxTable, columns
19+
820
from .template_code import MODULAR_COMPONENT_TEMPLATE_BUTTONS
921

1022
__all__ = (
@@ -27,7 +39,7 @@
2739
# Manufacturers
2840
#
2941

30-
class ManufacturerTable(NetBoxTable):
42+
class ManufacturerTable(ContactsColumnMixin, NetBoxTable):
3143
name = tables.Column(
3244
linkify=True
3345
)
@@ -43,9 +55,6 @@ class ManufacturerTable(NetBoxTable):
4355
verbose_name='Platforms'
4456
)
4557
slug = tables.Column()
46-
contacts = columns.ManyToManyColumn(
47-
linkify_item=True
48-
)
4958
tags = columns.TagColumn(
5059
url_name='dcim:manufacturer_list'
5160
)

netbox/dcim/tables/power.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import django_tables2 as tables
2-
32
from dcim.models import PowerFeed, PowerPanel
3+
from tenancy.tables import ContactsColumnMixin
4+
45
from netbox.tables import NetBoxTable, columns
6+
57
from .devices import CableTerminationTable
68

79
__all__ = (
@@ -14,7 +16,7 @@
1416
# Power panels
1517
#
1618

17-
class PowerPanelTable(NetBoxTable):
19+
class PowerPanelTable(ContactsColumnMixin, NetBoxTable):
1820
name = tables.Column(
1921
linkify=True
2022
)
@@ -29,9 +31,6 @@ class PowerPanelTable(NetBoxTable):
2931
url_params={'power_panel_id': 'pk'},
3032
verbose_name='Feeds'
3133
)
32-
contacts = columns.ManyToManyColumn(
33-
linkify_item=True
34-
)
3534
tags = columns.TagColumn(
3635
url_name='dcim:powerpanel_list'
3736
)

netbox/dcim/tables/racks.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import django_tables2 as tables
2+
from dcim.models import Rack, RackReservation, RackRole
23
from django_tables2.utils import Accessor
4+
from tenancy.tables import ContactsColumnMixin, TenancyColumnsMixin
35

4-
from dcim.models import Rack, RackReservation, RackRole
56
from netbox.tables import NetBoxTable, columns
6-
from tenancy.tables import TenancyColumnsMixin
77

88
__all__ = (
99
'RackTable',
@@ -37,7 +37,7 @@ class Meta(NetBoxTable.Meta):
3737
# Racks
3838
#
3939

40-
class RackTable(TenancyColumnsMixin, NetBoxTable):
40+
class RackTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
4141
name = tables.Column(
4242
order_by=('_name',),
4343
linkify=True
@@ -68,9 +68,6 @@ class RackTable(TenancyColumnsMixin, NetBoxTable):
6868
orderable=False,
6969
verbose_name='Power'
7070
)
71-
contacts = columns.ManyToManyColumn(
72-
linkify_item=True
73-
)
7471
tags = columns.TagColumn(
7572
url_name='dcim:rack_list'
7673
)

netbox/dcim/tables/sites.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import django_tables2 as tables
2-
32
from dcim.models import Location, Region, Site, SiteGroup
3+
from tenancy.tables import ContactsColumnMixin, TenancyColumnsMixin
4+
45
from netbox.tables import NetBoxTable, columns
5-
from tenancy.tables import TenancyColumnsMixin
6+
67
from .template_code import LOCATION_BUTTONS
78

89
__all__ = (
@@ -17,7 +18,7 @@
1718
# Regions
1819
#
1920

20-
class RegionTable(NetBoxTable):
21+
class RegionTable(ContactsColumnMixin, NetBoxTable):
2122
name = columns.MPTTColumn(
2223
linkify=True
2324
)
@@ -26,9 +27,6 @@ class RegionTable(NetBoxTable):
2627
url_params={'region_id': 'pk'},
2728
verbose_name='Sites'
2829
)
29-
contacts = columns.ManyToManyColumn(
30-
linkify_item=True
31-
)
3230
tags = columns.TagColumn(
3331
url_name='dcim:region_list'
3432
)
@@ -46,7 +44,7 @@ class Meta(NetBoxTable.Meta):
4644
# Site groups
4745
#
4846

49-
class SiteGroupTable(NetBoxTable):
47+
class SiteGroupTable(ContactsColumnMixin, NetBoxTable):
5048
name = columns.MPTTColumn(
5149
linkify=True
5250
)
@@ -55,9 +53,6 @@ class SiteGroupTable(NetBoxTable):
5553
url_params={'group_id': 'pk'},
5654
verbose_name='Sites'
5755
)
58-
contacts = columns.ManyToManyColumn(
59-
linkify_item=True
60-
)
6156
tags = columns.TagColumn(
6257
url_name='dcim:sitegroup_list'
6358
)
@@ -75,7 +70,7 @@ class Meta(NetBoxTable.Meta):
7570
# Sites
7671
#
7772

78-
class SiteTable(TenancyColumnsMixin, NetBoxTable):
73+
class SiteTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
7974
name = tables.Column(
8075
linkify=True
8176
)
@@ -97,9 +92,6 @@ class SiteTable(TenancyColumnsMixin, NetBoxTable):
9792
verbose_name='ASN Count'
9893
)
9994
comments = columns.MarkdownColumn()
100-
contacts = columns.ManyToManyColumn(
101-
linkify_item=True
102-
)
10395
tags = columns.TagColumn(
10496
url_name='dcim:site_list'
10597
)
@@ -118,7 +110,7 @@ class Meta(NetBoxTable.Meta):
118110
# Locations
119111
#
120112

121-
class LocationTable(TenancyColumnsMixin, NetBoxTable):
113+
class LocationTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
122114
name = columns.MPTTColumn(
123115
linkify=True
124116
)
@@ -136,9 +128,6 @@ class LocationTable(TenancyColumnsMixin, NetBoxTable):
136128
url_params={'location_id': 'pk'},
137129
verbose_name='Devices'
138130
)
139-
contacts = columns.ManyToManyColumn(
140-
linkify_item=True
141-
)
142131
tags = columns.TagColumn(
143132
url_name='dcim:location_list'
144133
)

netbox/tenancy/tables/columns.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import django_tables2 as tables
22

3+
from netbox.tables import columns
4+
35
__all__ = (
6+
'ContactsColumnMixin',
47
'TenantColumn',
58
'TenantGroupColumn',
69
'TenancyColumnsMixin',
@@ -55,3 +58,10 @@ def value(self, value):
5558
class TenancyColumnsMixin(tables.Table):
5659
tenant_group = TenantGroupColumn()
5760
tenant = TenantColumn()
61+
62+
63+
class ContactsColumnMixin(tables.Table):
64+
contacts = columns.ManyToManyColumn(
65+
linkify_item=True,
66+
transform=lambda obj: obj.contact.name
67+
)

netbox/tenancy/tables/tenants.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import django_tables2 as tables
2+
from tenancy.models import *
3+
from tenancy.tables import ContactsColumnMixin
24

35
from netbox.tables import NetBoxTable, columns
4-
from tenancy.models import *
56

67
__all__ = (
78
'TenantGroupTable',
@@ -30,17 +31,14 @@ class Meta(NetBoxTable.Meta):
3031
default_columns = ('pk', 'name', 'tenant_count', 'description')
3132

3233

33-
class TenantTable(NetBoxTable):
34+
class TenantTable(ContactsColumnMixin, NetBoxTable):
3435
name = tables.Column(
3536
linkify=True
3637
)
3738
group = tables.Column(
3839
linkify=True
3940
)
4041
comments = columns.MarkdownColumn()
41-
contacts = columns.ManyToManyColumn(
42-
linkify_item=True
43-
)
4442
tags = columns.TagColumn(
4543
url_name='tenancy:contact_list'
4644
)

0 commit comments

Comments
 (0)