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
@@ -212,30 +212,6 @@ class RegionListView(generic.ObjectListView):
212
212
class RegionView (generic .ObjectView ):
213
213
queryset = Region .objects .all ()
214
214
215
- def get_extra_context (self , request , instance ):
216
- child_regions = Region .objects .add_related_count (
217
- Region .objects .all (),
218
- Site ,
219
- 'region' ,
220
- 'site_count' ,
221
- cumulative = True
222
- ).restrict (request .user , 'view' ).filter (
223
- parent__in = instance .get_descendants (include_self = True )
224
- )
225
- child_regions_table = tables .RegionTable (child_regions )
226
- child_regions_table .columns .hide ('actions' )
227
-
228
- sites = Site .objects .restrict (request .user , 'view' ).filter (
229
- region = instance
230
- )
231
- sites_table = tables .SiteTable (sites , user = request .user , exclude = ('region' ,))
232
- sites_table .configure (request )
233
-
234
- return {
235
- 'child_regions_table' : child_regions_table ,
236
- 'sites_table' : sites_table ,
237
- }
238
-
239
215
240
216
@register_model_view (Region , 'edit' )
241
217
class RegionEditView (generic .ObjectEditView ):
@@ -300,30 +276,6 @@ class SiteGroupListView(generic.ObjectListView):
300
276
class SiteGroupView (generic .ObjectView ):
301
277
queryset = SiteGroup .objects .all ()
302
278
303
- def get_extra_context (self , request , instance ):
304
- child_groups = SiteGroup .objects .add_related_count (
305
- SiteGroup .objects .all (),
306
- Site ,
307
- 'group' ,
308
- 'site_count' ,
309
- cumulative = True
310
- ).restrict (request .user , 'view' ).filter (
311
- parent__in = instance .get_descendants (include_self = True )
312
- )
313
- child_groups_table = tables .SiteGroupTable (child_groups )
314
- child_groups_table .columns .hide ('actions' )
315
-
316
- sites = Site .objects .restrict (request .user , 'view' ).filter (
317
- group = instance
318
- )
319
- sites_table = tables .SiteTable (sites , user = request .user , exclude = ('group' ,))
320
- sites_table .configure (request )
321
-
322
- return {
323
- 'child_groups_table' : child_groups_table ,
324
- 'sites_table' : sites_table ,
325
- }
326
-
327
279
328
280
@register_model_view (SiteGroup , 'edit' )
329
281
class SiteGroupEditView (generic .ObjectEditView ):
@@ -493,22 +445,6 @@ def get_extra_context(self, request, instance):
493
445
rack_count = Rack .objects .filter (location__in = location_ids ).count ()
494
446
device_count = Device .objects .filter (location__in = location_ids ).count ()
495
447
496
- child_locations = Location .objects .add_related_count (
497
- Location .objects .add_related_count (
498
- Location .objects .all (),
499
- Device ,
500
- 'location' ,
501
- 'device_count' ,
502
- cumulative = True
503
- ),
504
- Rack ,
505
- 'location' ,
506
- 'rack_count' ,
507
- cumulative = True
508
- ).filter (pk__in = location_ids ).exclude (pk = instance .pk )
509
- child_locations_table = tables .LocationTable (child_locations , user = request .user )
510
- child_locations_table .configure (request )
511
-
512
448
nonracked_devices = Device .objects .filter (
513
449
location = instance ,
514
450
rack__isnull = True ,
@@ -518,7 +454,6 @@ def get_extra_context(self, request, instance):
518
454
return {
519
455
'rack_count' : rack_count ,
520
456
'device_count' : device_count ,
521
- 'child_locations_table' : child_locations_table ,
522
457
'nonracked_devices' : nonracked_devices .order_by ('-pk' )[:10 ],
523
458
'total_nonracked_devices_count' : nonracked_devices .count (),
524
459
}
@@ -583,20 +518,6 @@ class RackRoleListView(generic.ObjectListView):
583
518
class RackRoleView (generic .ObjectView ):
584
519
queryset = RackRole .objects .all ()
585
520
586
- def get_extra_context (self , request , instance ):
587
- racks = Rack .objects .restrict (request .user , 'view' ).filter (role = instance ).annotate (
588
- device_count = count_related (Device , 'rack' )
589
- )
590
-
591
- racks_table = tables .RackTable (racks , user = request .user , exclude = (
592
- 'role' , 'get_utilization' , 'get_power_utilization' ,
593
- ))
594
- racks_table .configure (request )
595
-
596
- return {
597
- 'racks_table' : racks_table ,
598
- }
599
-
600
521
601
522
@register_model_view (RackRole , 'edit' )
602
523
class RackRoleEditView (generic .ObjectEditView ):
@@ -859,8 +780,6 @@ class ManufacturerView(generic.ObjectView):
859
780
def get_extra_context (self , request , instance ):
860
781
device_types = DeviceType .objects .restrict (request .user , 'view' ).filter (
861
782
manufacturer = instance
862
- ).annotate (
863
- instance_count = count_related (Device , 'device_type' )
864
783
)
865
784
module_types = ModuleType .objects .restrict (request .user , 'view' ).filter (
866
785
manufacturer = instance
@@ -869,13 +788,10 @@ def get_extra_context(self, request, instance):
869
788
manufacturer = instance
870
789
)
871
790
872
- devicetypes_table = tables .DeviceTypeTable (device_types , user = request .user , exclude = ('manufacturer' ,))
873
- devicetypes_table .configure (request )
874
-
875
791
return {
876
- 'devicetypes_table ' : devicetypes_table ,
877
- 'inventory_item_count ' : inventory_items .count (),
878
- 'module_type_count ' : module_types .count (),
792
+ 'devicetype_count ' : device_types . count () ,
793
+ 'inventoryitem_count ' : inventory_items .count (),
794
+ 'moduletype_count ' : module_types .count (),
879
795
}
880
796
881
797
@@ -1726,19 +1642,6 @@ class DeviceRoleListView(generic.ObjectListView):
1726
1642
class DeviceRoleView (generic .ObjectView ):
1727
1643
queryset = DeviceRole .objects .all ()
1728
1644
1729
- def get_extra_context (self , request , instance ):
1730
- devices = Device .objects .restrict (request .user , 'view' ).filter (
1731
- device_role = instance
1732
- )
1733
- devices_table = tables .DeviceTable (devices , user = request .user , exclude = ('device_role' ,))
1734
- devices_table .configure (request )
1735
-
1736
- return {
1737
- 'devices_table' : devices_table ,
1738
- 'device_count' : Device .objects .filter (device_role = instance ).count (),
1739
- 'virtualmachine_count' : VirtualMachine .objects .filter (role = instance ).count (),
1740
- }
1741
-
1742
1645
1743
1646
@register_model_view (DeviceRole , 'devices' , path = 'devices' )
1744
1647
class DeviceRoleDevicesView (generic .ObjectChildrenView ):
@@ -1833,12 +1736,13 @@ def get_extra_context(self, request, instance):
1833
1736
devices = Device .objects .restrict (request .user , 'view' ).filter (
1834
1737
platform = instance
1835
1738
)
1836
- devices_table = tables .DeviceTable (devices , user = request .user , exclude = ('platform' ,))
1837
- devices_table .configure (request )
1739
+ virtual_machines = VirtualMachine .objects .restrict (request .user , 'view' ).filter (
1740
+ platform = instance
1741
+ )
1838
1742
1839
1743
return {
1840
- 'devices_table ' : devices_table ,
1841
- 'virtualmachine_count' : VirtualMachine . objects . filter ( platform = instance ) .count ()
1744
+ 'device_count ' : devices . count () ,
1745
+ 'virtualmachine_count' : virtual_machines .count ()
1842
1746
}
1843
1747
1844
1748
@@ -2520,12 +2424,6 @@ def get_extra_context(self, request, instance):
2520
2424
orderable = False
2521
2425
)
2522
2426
2523
- # Get assigned IP addresses
2524
- ipaddress_table = AssignedIPAddressesTable (
2525
- data = instance .ip_addresses .restrict (request .user , 'view' ).prefetch_related ('vrf' , 'tenant' ),
2526
- orderable = False
2527
- )
2528
-
2529
2427
# Get bridge interfaces
2530
2428
bridge_interfaces = Interface .objects .restrict (request .user , 'view' ).filter (bridge = instance )
2531
2429
bridge_interfaces_tables = tables .InterfaceTable (
@@ -2558,7 +2456,6 @@ def get_extra_context(self, request, instance):
2558
2456
2559
2457
return {
2560
2458
'vdc_table' : vdc_table ,
2561
- 'ipaddress_table' : ipaddress_table ,
2562
2459
'bridge_interfaces_table' : bridge_interfaces_tables ,
2563
2460
'child_interfaces_table' : child_interfaces_tables ,
2564
2461
'vlan_table' : vlan_table ,
@@ -3533,20 +3430,6 @@ class PowerPanelListView(generic.ObjectListView):
3533
3430
class PowerPanelView (generic .ObjectView ):
3534
3431
queryset = PowerPanel .objects .all ()
3535
3432
3536
- def get_extra_context (self , request , instance ):
3537
- power_feeds = PowerFeed .objects .restrict (request .user ).filter (power_panel = instance )
3538
- powerfeed_table = tables .PowerFeedTable (
3539
- data = power_feeds ,
3540
- orderable = False
3541
- )
3542
- if request .user .has_perm ('dcim.delete_cable' ):
3543
- powerfeed_table .columns .show ('pk' )
3544
- powerfeed_table .exclude = ['power_panel' ]
3545
-
3546
- return {
3547
- 'powerfeed_table' : powerfeed_table ,
3548
- }
3549
-
3550
3433
3551
3434
@register_model_view (PowerPanel , 'edit' )
3552
3435
class PowerPanelEditView (generic .ObjectEditView ):
@@ -3648,16 +3531,6 @@ class VirtualDeviceContextListView(generic.ObjectListView):
3648
3531
class VirtualDeviceContextView (generic .ObjectView ):
3649
3532
queryset = VirtualDeviceContext .objects .all ()
3650
3533
3651
- def get_extra_context (self , request , instance ):
3652
- interfaces_table = tables .InterfaceTable (instance .interfaces , user = request .user )
3653
- interfaces_table .configure (request )
3654
- interfaces_table .columns .hide ('device' )
3655
-
3656
- return {
3657
- 'interfaces_table' : interfaces_table ,
3658
- 'interface_count' : instance .interfaces .count (),
3659
- }
3660
-
3661
3534
3662
3535
@register_model_view (VirtualDeviceContext , 'edit' )
3663
3536
class VirtualDeviceContextEditView (generic .ObjectEditView ):
0 commit comments