Skip to content

Commit 6cf5dfd

Browse files
committed
fixed rack list and unracked-device list in edit view mess-up
1 parent 755ff30 commit 6cf5dfd

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

netbox_floorplan/tables.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
from netbox.tables import NetBoxTable
44
from .models import Floorplan, FloorplanImage
5+
from functools import cached_property
6+
from django.urls.exceptions import NoReverseMatch
57

6-
from dcim.models import Rack
8+
from dcim.models import Rack, Device
9+
10+
from utilities.views import get_action_url
711

812

913
class FloorplanImageTable(NetBoxTable):
@@ -32,14 +36,19 @@ class Meta(NetBoxTable.Meta):
3236

3337

3438
class FloorplanRackTable(NetBoxTable):
35-
3639
name = tables.LinkColumn()
40+
embedded = True
3741

3842
actions = tables.TemplateColumn(template_code="""
3943
<a type="button" class="btn btn-sm btn-outline-info" onclick="add_floorplan_object(300, 500, '{{ record.outer_width }}', '{{ record.outer_depth}}', '{{ record.outer_unit }}', '#ea8fe', 30, '{{ record.id }}', '{{ record.name }}', 'rack', '{{ record.status }}')">Add Rack
4044
</a>
4145
""")
4246

47+
@cached_property
48+
def htmx_url(self):
49+
# no need to check for embedded as this table is always embedded
50+
return "/plugins/floorplan/floorplans/racks/"
51+
4352
class Meta(NetBoxTable.Meta):
4453
model = Rack
4554
fields = ('pk', 'name', 'u_height')
@@ -48,18 +57,23 @@ class Meta(NetBoxTable.Meta):
4857
'id': lambda record: 'object_rack_{}'.format(record.pk),
4958
}
5059

51-
5260
class FloorplanDeviceTable(NetBoxTable):
53-
5461
name = tables.LinkColumn()
62+
embedded = True
5563

5664
actions = tables.TemplateColumn(template_code="""
5765
<a type="button" class="btn btn-sm btn-outline-info" onclick="add_floorplan_object(30, 50, 60, 60, '{{ record.outer_unit }}', '#ea8fe', 30, '{{ record.id }}', '{{ record.name }}', 'device', '{{ record.status }}', '{{ record.device_type.front_image }}')">Add Device
5866
</a>
5967
""")
6068

69+
@cached_property
70+
def htmx_url(self):
71+
# no need to check for embedded as this table is always embedded
72+
return "/plugins/floorplan/floorplans/devices/"
73+
74+
6175
class Meta(NetBoxTable.Meta):
62-
model = Rack
76+
model = Device
6377
fields = ('pk', 'name', 'device_type')
6478
default_columns = ('pk', 'name', 'device_type')
6579
row_attrs = {

0 commit comments

Comments
 (0)