Преглед изворни кода

Closes #7504: Include IP range data under IPAM role views

jeremystretch пре 4 година
родитељ
комит
4f4e6938eb

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

@@ -4,6 +4,7 @@
 
 ### Enhancements
 
+* [#7504](https://github.com/netbox-community/netbox/issues/7504) - Include IP range data under IPAM role views
 * [#8275](https://github.com/netbox-community/netbox/issues/8275) - Introduce alternative ASDOT-formatted column for ASNs
 * [#8367](https://github.com/netbox-community/netbox/issues/8367) - Add ASNs to global search function
 * [#8368](https://github.com/netbox-community/netbox/issues/8368) - Enable controlling the order of custom script form fields with `field_order`

+ 8 - 3
netbox/ipam/tables/ip.py

@@ -184,6 +184,11 @@ class RoleTable(BaseTable):
         url_params={'role_id': 'pk'},
         verbose_name='Prefixes'
     )
+    iprange_count = LinkedCountColumn(
+        viewname='ipam:iprange_list',
+        url_params={'role_id': 'pk'},
+        verbose_name='IP Ranges'
+    )
     vlan_count = LinkedCountColumn(
         viewname='ipam:vlan_list',
         url_params={'role_id': 'pk'},
@@ -197,10 +202,10 @@ class RoleTable(BaseTable):
     class Meta(BaseTable.Meta):
         model = Role
         fields = (
-            'pk', 'id', 'name', 'slug', 'prefix_count', 'vlan_count', 'description', 'weight', 'tags', 'actions',
-            'created', 'last_updated',
+            'pk', 'id', 'name', 'slug', 'prefix_count', 'iprange_count', 'vlan_count', 'description', 'weight', 'tags',
+            'actions', 'created', 'last_updated',
         )
-        default_columns = ('pk', 'name', 'prefix_count', 'vlan_count', 'description', 'actions')
+        default_columns = ('pk', 'name', 'prefix_count', 'iprange_count', 'vlan_count', 'description', 'actions')
 
 
 #

+ 1 - 0
netbox/ipam/views.py

@@ -340,6 +340,7 @@ class AggregateBulkDeleteView(generic.BulkDeleteView):
 class RoleListView(generic.ObjectListView):
     queryset = Role.objects.annotate(
         prefix_count=count_related(Prefix, 'role'),
+        iprange_count=count_related(IPRange, 'role'),
         vlan_count=count_related(VLAN, 'role')
     )
     filterset = filtersets.RoleFilterSet

+ 24 - 0
netbox/templates/ipam/role.html

@@ -38,6 +38,30 @@
               <a href="{% url 'ipam:prefix_list' %}?role_id={{ object.pk }}">{{ prefixes_table.rows|length }}</a>
             </td>
           </tr>
+          <tr>
+            <th scope="row">IP Ranges</th>
+            <td>
+              {% with ipranges_count=object.ip_ranges.count %}
+                {% if ipranges_count %}
+                  <a href="{% url 'ipam:iprange_list' %}?role_id={{ object.pk }}">{{ ipranges_count }}</a>
+                {% else %}
+                  &mdash;
+                {% endif %}
+              {% endwith %}
+            </td>
+          </tr>
+          <tr>
+            <th scope="row">VLANs</th>
+            <td>
+              {% with vlans_count=object.vlans.count %}
+                {% if vlans_count %}
+                  <a href="{% url 'ipam:vlan_list' %}?role_id={{ object.pk }}">{{ vlans_count }}</a>
+                {% else %}
+                  &mdash;
+                {% endif %}
+              {% endwith %}
+            </td>
+          </tr>
         </table>
       </div>
     </div>