Просмотр исходного кода

Fixes #6433: Fix bulk editing of child prefixes under aggregate view

jeremystretch 4 лет назад
Родитель
Сommit
1be748b479

+ 1 - 0
docs/release-notes/version-3.0.md

@@ -11,6 +11,7 @@
 
 ### Bug Fixes
 
+* [#6433](https://github.com/netbox-community/netbox/issues/6433) - Fix bulk editing of child prefixes under aggregate view
 * [#6895](https://github.com/netbox-community/netbox/issues/6895) - Remove errant markup for null values in CSV export
 * [#7373](https://github.com/netbox-community/netbox/issues/7373) - Fix flashing when server, client, and browser color-mode preferences are mismatched
 * [#7397](https://github.com/netbox-community/netbox/issues/7397) - Fix AttributeError exception when rendering export template for devices via REST API

+ 1 - 0
netbox/ipam/views.py

@@ -240,6 +240,7 @@ class AggregateView(generic.ObjectView):
         return {
             'prefix_table': prefix_table,
             'permissions': permissions,
+            'bulk_querystring': f'within={instance.prefix}',
             'show_available': request.GET.get('show_available', 'true') == 'true',
         }
 

+ 3 - 3
netbox/templates/ipam/aggregate.html

@@ -75,8 +75,8 @@
     </div>
 </div>
 <div class="row mb-3">
-    <div class="col col-md-12">
-        {% include 'utilities/obj_table.html' with table=prefix_table heading='Child Prefixes' bulk_edit_url='ipam:prefix_bulk_edit' bulk_delete_url='ipam:prefix_bulk_delete' %}
-	  </div>
+  <div class="col col-md-12">
+    {% include 'utilities/obj_table.html' with table=prefix_table heading='Child Prefixes' bulk_edit_url='ipam:prefix_bulk_edit' bulk_delete_url='ipam:prefix_bulk_delete' %}
+  </div>
 </div>
 {% endblock %}

+ 1 - 1
netbox/templates/utilities/obj_table.html

@@ -24,7 +24,7 @@
                 <div class="form-check">
                     <input type="checkbox" id="select-all" name="_all" class="form-check-input" />
                     <label for="select-all" class="form-check-label">
-                    Select <strong>all {{ table.rows|length }} {{ table.data.verbose_name_plural }}</strong> matching query
+                    Select <strong>all {{ table.objects_count }} {{ table.data.verbose_name_plural }}</strong> matching query
                     </label>
                 </div>
               </div>

+ 10 - 0
netbox/utilities/tables.py

@@ -111,6 +111,16 @@ class BaseTable(tables.Table):
     def selected_columns(self):
         return self._get_columns(visible=True)
 
+    @property
+    def objects_count(self):
+        """
+        Return the total number of real objects represented by the Table. This is useful when dealing with
+        prefixes/IP addresses/etc., where some table rows may represent available address space.
+        """
+        if not hasattr(self, '_objects_count'):
+            self._objects_count = sum(1 for obj in self.data if getattr(obj, 'pk'))
+        return self._objects_count
+
 
 #
 # Table columns