فهرست منبع

Fixes #7072: Fix table configuration under prefix child object views

jeremystretch 4 سال پیش
والد
کامیت
7db2b9d091

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

@@ -6,6 +6,7 @@
 
 * [#7070](https://github.com/netbox-community/netbox/issues/7070) - Fix exception when filtering by prefix max length in UI
 * [#7071](https://github.com/netbox-community/netbox/issues/7071) - Fix exception when removing a primary IP from a device/VM
+* [#7072](https://github.com/netbox-community/netbox/issues/7072) - Fix table configuration under prefix child object views
 * [#7083](https://github.com/netbox-community/netbox/issues/7083) - Correct labeling for VM memory attribute
 * [#7084](https://github.com/netbox-community/netbox/issues/7084) - Fix KeyError exception when editing access VLAN on an interface
 * [#7096](https://github.com/netbox-community/netbox/issues/7096) - Home links should honor `BASE_PATH` configuration

+ 4 - 5
netbox/ipam/views.py

@@ -404,12 +404,11 @@ class PrefixPrefixesView(generic.ObjectView):
         bulk_querystring = 'vrf_id={}&within={}'.format(instance.vrf.pk if instance.vrf else '0', instance.prefix)
 
         return {
-            'first_available_prefix': instance.get_first_available_prefix(),
             'table': table,
             'bulk_querystring': bulk_querystring,
             'active_tab': 'prefixes',
+            'first_available_prefix': instance.get_first_available_prefix(),
             'show_available': request.GET.get('show_available', 'true') == 'true',
-            'table_config_form': TableConfigForm(table=table),
         }
 
 
@@ -421,7 +420,7 @@ class PrefixIPRangesView(generic.ObjectView):
         # Find all IPRanges belonging to this Prefix
         ip_ranges = instance.get_child_ranges().restrict(request.user, 'view').prefetch_related('vrf')
 
-        table = tables.IPRangeTable(ip_ranges)
+        table = tables.IPRangeTable(ip_ranges, user=request.user)
         if request.user.has_perm('ipam.change_iprange') or request.user.has_perm('ipam.delete_iprange'):
             table.columns.show('pk')
         paginate_table(table, request)
@@ -449,7 +448,7 @@ class PrefixIPAddressesView(generic.ObjectView):
         if request.GET.get('show_available', 'true') == 'true':
             ipaddresses = add_available_ipaddresses(instance.prefix, ipaddresses, instance.is_pool)
 
-        table = tables.IPAddressTable(ipaddresses)
+        table = tables.IPAddressTable(ipaddresses, user=request.user)
         if request.user.has_perm('ipam.change_ipaddress') or request.user.has_perm('ipam.delete_ipaddress'):
             table.columns.show('pk')
         paginate_table(table, request)
@@ -457,10 +456,10 @@ class PrefixIPAddressesView(generic.ObjectView):
         bulk_querystring = 'vrf_id={}&parent={}'.format(instance.vrf.pk if instance.vrf else '0', instance.prefix)
 
         return {
-            'first_available_ip': instance.get_first_available_ip(),
             'table': table,
             'bulk_querystring': bulk_querystring,
             'active_tab': 'ip-addresses',
+            'first_available_ip': instance.get_first_available_ip(),
             'show_available': request.GET.get('show_available', 'true') == 'true',
         }
 

+ 0 - 1
netbox/netbox/views/generic.py

@@ -181,7 +181,6 @@ class ObjectListView(ObjectPermissionRequiredMixin, View):
             'table': table,
             'permissions': permissions,
             'action_buttons': self.action_buttons,
-            'table_config_form': TableConfigForm(table=table),
             'filter_form': self.filterset_form(request.GET, label_suffix='') if self.filterset_form else None,
         }
         context.update(self.extra_context())

+ 8 - 0
netbox/templates/ipam/prefix/ip_addresses.html

@@ -1,4 +1,6 @@
 {% extends 'ipam/prefix/base.html' %}
+{% load helpers %}
+{% load static %}
 
 {% block extra_controls %}
   {% if perms.ipam.add_ipaddress and active_tab == 'ip-addresses' and first_available_ip %}
@@ -11,7 +13,13 @@
 {% block content %}
   <div class="row">
     <div class="col col-md-12">
+      {% include 'inc/table_controls.html' with table_modal="IPAddressTable_config" %}
       {% include 'utilities/obj_table.html' with heading='IP Addresses' bulk_edit_url='ipam:ipaddress_bulk_edit' bulk_delete_url='ipam:ipaddress_bulk_delete' %}
     </div>
   </div>
+  {% table_config_form table table_name="IPAddressTable" %}
+{% endblock %}
+
+{% block javascript %}
+  <script src="{% static 'js/tableconfig.js' %}"></script>
 {% endblock %}

+ 8 - 1
netbox/templates/ipam/prefix/ip_ranges.html

@@ -1,10 +1,17 @@
 {% extends 'ipam/prefix/base.html' %}
-
+{% load helpers %}
+{% load static %}
 
 {% block content %}
   <div class="row">
     <div class="col col-md-12">
+      {% include 'inc/table_controls.html' with table_modal="IPRangeTable_config" %}
       {% include 'utilities/obj_table.html' with heading='Child IP Ranges' bulk_edit_url='ipam:prefix_bulk_edit' bulk_delete_url='ipam:prefix_bulk_delete' parent=prefix %}
     </div>
   </div>
+  {% table_config_form table table_name="IPRangeTable" %}
+{% endblock %}
+
+{% block javascript %}
+  <script src="{% static 'js/tableconfig.js' %}"></script>
 {% endblock %}

+ 7 - 9
netbox/templates/ipam/prefix/prefixes.html

@@ -2,20 +2,17 @@
 {% load helpers %}
 {% load static %}
 
-{% block buttons %}
+{% block extra_controls %}
   {% include 'ipam/inc/toggle_available.html' %}
-  {% if request.user.is_authenticated and table_config_form %}
-      <button type="button" class="btn btn-default" data-toggle="modal" data-target="#PrefixDetailTable_config" title="Configure table"><i class="mdi mdi-cog"></i> Configure</button>
-  {% endif %}
   {% if perms.ipam.add_prefix and active_tab == 'prefixes' and first_available_prefix %}
-    <a href="{% url 'ipam:prefix_add' %}?prefix={{ first_available_prefix }}&vrf={{ object.vrf.pk }}&site={{ object.site.pk }}&tenant_group={{ object.tenant.group.pk }}&tenant={{ object.tenant.pk }}" class="btn btn-success">
+    <a href="{% url 'ipam:prefix_add' %}?prefix={{ first_available_prefix }}&vrf={{ object.vrf.pk }}&site={{ object.site.pk }}&tenant_group={{ object.tenant.group.pk }}&tenant={{ object.tenant.pk }}" class="btn btn-sm btn-success">
       <i class="mdi mdi-plus-thick" aria-hidden="true"></i> Add Child Prefix
     </a>
   {% endif %}
   {% if perms.ipam.add_ipaddress and active_tab == 'ip-addresses' and first_available_ip %}
-    <a href="{% url 'ipam:ipaddress_add' %}?address={{ first_available_ip }}&vrf={{ object.vrf.pk }}&tenant_group={{ object.tenant.group.pk }}&tenant={{ object.tenant.pk }}" class="btn btn-success">
+    <a href="{% url 'ipam:ipaddress_add' %}?address={{ first_available_ip }}&vrf={{ object.vrf.pk }}&tenant_group={{ object.tenant.group.pk }}&tenant={{ object.tenant.pk }}" class="btn btn-sm btn-success">
       <span class="mdi mdi-plus-thick" aria-hidden="true"></span>
-      Add an IP Address
+      Add Child IP Address
     </a>
   {% endif %}
   {{ block.super }}
@@ -24,12 +21,13 @@
 {% block content %}
   <div class="row">
     <div class="col col-md-12">
+      {% include 'inc/table_controls.html' with table_modal="PrefixDetailTable_config" %}
       {% include 'utilities/obj_table.html' with heading='Child Prefixes' bulk_edit_url='ipam:prefix_bulk_edit' bulk_delete_url='ipam:prefix_bulk_delete' parent=prefix %}
     </div>
   </div>
-  {% table_config_form prefix_table table_name="PrefixDetailTable" %}
+  {% table_config_form table table_name="PrefixDetailTable" %}
 {% endblock %}
 
 {% block javascript %}
-<script src="{% static 'js/tableconfig.js' %}"></script>
+  <script src="{% static 'js/tableconfig.js' %}"></script>
 {% endblock %}

+ 5 - 5
netbox/templates/utilities/templatetags/table_config_form.html

@@ -7,11 +7,11 @@
         <h5 class="modal-title">Table Configuration</h5>
         <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
       </div>
-      <form class="form-horizontal userconfigform" data-config-root="tables.{{ table_config_form.table_name }}">
+      <form class="form-horizontal userconfigform" data-config-root="tables.{{ form.table_name }}">
         <div class="modal-body row">
           <div class="col-5 text-center">
-            {{ table_config_form.available_columns.label }}
-            {{ table_config_form.available_columns }}
+            {{ form.available_columns.label }}
+            {{ form.available_columns }}
           </div>
           <div class="col-2 d-flex align-items-center">
             <div>
@@ -24,8 +24,8 @@
             </div>
           </div>
           <div class="col-5 text-center">
-            {{ table_config_form.columns.label }}
-            {{ table_config_form.columns }}
+            {{ form.columns.label }}
+            {{ form.columns }}
             <a class="btn btn-primary btn-sm mt-2" id="move-option-up" data-target="id_columns">
                 <i class="mdi mdi-arrow-up-bold"></i> Move Up
             </a>

+ 1 - 1
netbox/utilities/templatetags/helpers.py

@@ -401,7 +401,7 @@ def badge(value, bg_class='secondary', show_empty=False):
 def table_config_form(table, table_name=None):
     return {
         'table_name': table_name or table.__class__.__name__,
-        'table_config_form': TableConfigForm(table=table),
+        'form': TableConfigForm(table=table),
     }