14
14
from circuits .models import Circuit , CircuitTermination
15
15
from extras .views import ObjectConfigContextView
16
16
from ipam .models import ASN , IPAddress , Prefix , Service , VLAN , VLANGroup
17
- from ipam .tables import AssignedIPAddressesTable , InterfaceVLANTable
17
+ from ipam .tables import InterfaceVLANTable
18
18
from netbox .views import generic
19
19
from utilities .forms import ConfirmationForm
20
20
from utilities .paginator import EnhancedPaginator , get_paginate_count
@@ -210,30 +210,6 @@ class RegionListView(generic.ObjectListView):
210
210
class RegionView (generic .ObjectView ):
211
211
queryset = Region .objects .all ()
212
212
213
- def get_extra_context (self , request , instance ):
214
- child_regions = Region .objects .add_related_count (
215
- Region .objects .all (),
216
- Site ,
217
- 'region' ,
218
- 'site_count' ,
219
- cumulative = True
220
- ).restrict (request .user , 'view' ).filter (
221
- parent__in = instance .get_descendants (include_self = True )
222
- )
223
- child_regions_table = tables .RegionTable (child_regions )
224
- child_regions_table .columns .hide ('actions' )
225
-
226
- sites = Site .objects .restrict (request .user , 'view' ).filter (
227
- region = instance
228
- )
229
- sites_table = tables .SiteTable (sites , user = request .user , exclude = ('region' ,))
230
- sites_table .configure (request )
231
-
232
- return {
233
- 'child_regions_table' : child_regions_table ,
234
- 'sites_table' : sites_table ,
235
- }
236
-
237
213
238
214
@register_model_view (Region , 'edit' )
239
215
class RegionEditView (generic .ObjectEditView ):
@@ -298,30 +274,6 @@ class SiteGroupListView(generic.ObjectListView):
298
274
class SiteGroupView (generic .ObjectView ):
299
275
queryset = SiteGroup .objects .all ()
300
276
301
- def get_extra_context (self , request , instance ):
302
- child_groups = SiteGroup .objects .add_related_count (
303
- SiteGroup .objects .all (),
304
- Site ,
305
- 'group' ,
306
- 'site_count' ,
307
- cumulative = True
308
- ).restrict (request .user , 'view' ).filter (
309
- parent__in = instance .get_descendants (include_self = True )
310
- )
311
- child_groups_table = tables .SiteGroupTable (child_groups )
312
- child_groups_table .columns .hide ('actions' )
313
-
314
- sites = Site .objects .restrict (request .user , 'view' ).filter (
315
- group = instance
316
- )
317
- sites_table = tables .SiteTable (sites , user = request .user , exclude = ('group' ,))
318
- sites_table .configure (request )
319
-
320
- return {
321
- 'child_groups_table' : child_groups_table ,
322
- 'sites_table' : sites_table ,
323
- }
324
-
325
277
326
278
@register_model_view (SiteGroup , 'edit' )
327
279
class SiteGroupEditView (generic .ObjectEditView ):
@@ -491,22 +443,6 @@ def get_extra_context(self, request, instance):
491
443
rack_count = Rack .objects .filter (location__in = location_ids ).count ()
492
444
device_count = Device .objects .filter (location__in = location_ids ).count ()
493
445
494
- child_locations = Location .objects .add_related_count (
495
- Location .objects .add_related_count (
496
- Location .objects .all (),
497
- Device ,
498
- 'location' ,
499
- 'device_count' ,
500
- cumulative = True
501
- ),
502
- Rack ,
503
- 'location' ,
504
- 'rack_count' ,
505
- cumulative = True
506
- ).filter (pk__in = location_ids ).exclude (pk = instance .pk )
507
- child_locations_table = tables .LocationTable (child_locations , user = request .user )
508
- child_locations_table .configure (request )
509
-
510
446
nonracked_devices = Device .objects .filter (
511
447
location = instance ,
512
448
rack__isnull = True ,
@@ -516,7 +452,6 @@ def get_extra_context(self, request, instance):
516
452
return {
517
453
'rack_count' : rack_count ,
518
454
'device_count' : device_count ,
519
- 'child_locations_table' : child_locations_table ,
520
455
'nonracked_devices' : nonracked_devices .order_by ('-pk' )[:10 ],
521
456
'total_nonracked_devices_count' : nonracked_devices .count (),
522
457
}
@@ -581,20 +516,6 @@ class RackRoleListView(generic.ObjectListView):
581
516
class RackRoleView (generic .ObjectView ):
582
517
queryset = RackRole .objects .all ()
583
518
584
- def get_extra_context (self , request , instance ):
585
- racks = Rack .objects .restrict (request .user , 'view' ).filter (role = instance ).annotate (
586
- device_count = count_related (Device , 'rack' )
587
- )
588
-
589
- racks_table = tables .RackTable (racks , user = request .user , exclude = (
590
- 'role' , 'get_utilization' , 'get_power_utilization' ,
591
- ))
592
- racks_table .configure (request )
593
-
594
- return {
595
- 'racks_table' : racks_table ,
596
- }
597
-
598
519
599
520
@register_model_view (RackRole , 'edit' )
600
521
class RackRoleEditView (generic .ObjectEditView ):
@@ -855,8 +776,6 @@ class ManufacturerView(generic.ObjectView):
855
776
def get_extra_context (self , request , instance ):
856
777
device_types = DeviceType .objects .restrict (request .user , 'view' ).filter (
857
778
manufacturer = instance
858
- ).annotate (
859
- instance_count = count_related (Device , 'device_type' )
860
779
)
861
780
module_types = ModuleType .objects .restrict (request .user , 'view' ).filter (
862
781
manufacturer = instance
@@ -865,13 +784,10 @@ def get_extra_context(self, request, instance):
865
784
manufacturer = instance
866
785
)
867
786
868
- devicetypes_table = tables .DeviceTypeTable (device_types , user = request .user , exclude = ('manufacturer' ,))
869
- devicetypes_table .configure (request )
870
-
871
787
return {
872
- 'devicetypes_table ' : devicetypes_table ,
873
- 'inventory_item_count ' : inventory_items .count (),
874
- 'module_type_count ' : module_types .count (),
788
+ 'devicetype_count ' : device_types . count () ,
789
+ 'inventoryitem_count ' : inventory_items .count (),
790
+ 'moduletype_count ' : module_types .count (),
875
791
}
876
792
877
793
@@ -1722,19 +1638,6 @@ class DeviceRoleListView(generic.ObjectListView):
1722
1638
class DeviceRoleView (generic .ObjectView ):
1723
1639
queryset = DeviceRole .objects .all ()
1724
1640
1725
- def get_extra_context (self , request , instance ):
1726
- devices = Device .objects .restrict (request .user , 'view' ).filter (
1727
- device_role = instance
1728
- )
1729
- devices_table = tables .DeviceTable (devices , user = request .user , exclude = ('device_role' ,))
1730
- devices_table .configure (request )
1731
-
1732
- return {
1733
- 'devices_table' : devices_table ,
1734
- 'device_count' : Device .objects .filter (device_role = instance ).count (),
1735
- 'virtualmachine_count' : VirtualMachine .objects .filter (role = instance ).count (),
1736
- }
1737
-
1738
1641
1739
1642
@register_model_view (DeviceRole , 'edit' )
1740
1643
class DeviceRoleEditView (generic .ObjectEditView ):
@@ -1793,12 +1696,13 @@ def get_extra_context(self, request, instance):
1793
1696
devices = Device .objects .restrict (request .user , 'view' ).filter (
1794
1697
platform = instance
1795
1698
)
1796
- devices_table = tables .DeviceTable (devices , user = request .user , exclude = ('platform' ,))
1797
- devices_table .configure (request )
1699
+ virtual_machines = VirtualMachine .objects .restrict (request .user , 'view' ).filter (
1700
+ platform = instance
1701
+ )
1798
1702
1799
1703
return {
1800
- 'devices_table ' : devices_table ,
1801
- 'virtualmachine_count' : VirtualMachine . objects . filter ( platform = instance ) .count ()
1704
+ 'device_count ' : devices . count () ,
1705
+ 'virtualmachine_count' : virtual_machines .count ()
1802
1706
}
1803
1707
1804
1708
@@ -2487,12 +2391,6 @@ def get_extra_context(self, request, instance):
2487
2391
orderable = False
2488
2392
)
2489
2393
2490
- # Get assigned IP addresses
2491
- ipaddress_table = AssignedIPAddressesTable (
2492
- data = instance .ip_addresses .restrict (request .user , 'view' ).prefetch_related ('vrf' , 'tenant' ),
2493
- orderable = False
2494
- )
2495
-
2496
2394
# Get bridge interfaces
2497
2395
bridge_interfaces = Interface .objects .restrict (request .user , 'view' ).filter (bridge = instance )
2498
2396
bridge_interfaces_tables = tables .InterfaceTable (
@@ -2525,7 +2423,6 @@ def get_extra_context(self, request, instance):
2525
2423
2526
2424
return {
2527
2425
'vdc_table' : vdc_table ,
2528
- 'ipaddress_table' : ipaddress_table ,
2529
2426
'bridge_interfaces_table' : bridge_interfaces_tables ,
2530
2427
'child_interfaces_table' : child_interfaces_tables ,
2531
2428
'vlan_table' : vlan_table ,
@@ -3500,20 +3397,6 @@ class PowerPanelListView(generic.ObjectListView):
3500
3397
class PowerPanelView (generic .ObjectView ):
3501
3398
queryset = PowerPanel .objects .all ()
3502
3399
3503
- def get_extra_context (self , request , instance ):
3504
- power_feeds = PowerFeed .objects .restrict (request .user ).filter (power_panel = instance )
3505
- powerfeed_table = tables .PowerFeedTable (
3506
- data = power_feeds ,
3507
- orderable = False
3508
- )
3509
- if request .user .has_perm ('dcim.delete_cable' ):
3510
- powerfeed_table .columns .show ('pk' )
3511
- powerfeed_table .exclude = ['power_panel' ]
3512
-
3513
- return {
3514
- 'powerfeed_table' : powerfeed_table ,
3515
- }
3516
-
3517
3400
3518
3401
@register_model_view (PowerPanel , 'edit' )
3519
3402
class PowerPanelEditView (generic .ObjectEditView ):
@@ -3615,16 +3498,6 @@ class VirtualDeviceContextListView(generic.ObjectListView):
3615
3498
class VirtualDeviceContextView (generic .ObjectView ):
3616
3499
queryset = VirtualDeviceContext .objects .all ()
3617
3500
3618
- def get_extra_context (self , request , instance ):
3619
- interfaces_table = tables .InterfaceTable (instance .interfaces , user = request .user )
3620
- interfaces_table .configure (request )
3621
- interfaces_table .columns .hide ('device' )
3622
-
3623
- return {
3624
- 'interfaces_table' : interfaces_table ,
3625
- 'interface_count' : instance .interfaces .count (),
3626
- }
3627
-
3628
3501
3629
3502
@register_model_view (VirtualDeviceContext , 'edit' )
3630
3503
class VirtualDeviceContextEditView (generic .ObjectEditView ):
0 commit comments