Kaynağa Gözat

Introduce table_config_form template tag to simplify form generation

Jeremy Stretch 5 yıl önce
ebeveyn
işleme
ce2210b7bc

+ 54 - 1
netbox/templates/dcim/device.html

@@ -485,8 +485,11 @@
                         <div class="panel panel-default">
                         <div class="panel panel-default">
                             <div class="panel-heading">
                             <div class="panel-heading">
                                 <strong>Interfaces</strong>
                                 <strong>Interfaces</strong>
-                                <div class="col-md-2 pull-right noprint">
+                                <div class="pull-right noprint">
                                     <input class="form-control interface-filter" type="text" placeholder="Filter" title="Filter text (regular expressions supported)" style="height: 23px" />
                                     <input class="form-control interface-filter" type="text" placeholder="Filter" title="Filter text (regular expressions supported)" style="height: 23px" />
+                                    {% if request.user.is_authenticated %}
+                                        <button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#DeviceInterfaceTable_config" title="Configure table"><i class="fa fa-cog"></i> Configure</button>
+                                    {% endif %}
                                 </div>
                                 </div>
                             </div>
                             </div>
                             {% include 'responsive_table.html' with table=interface_table %}
                             {% include 'responsive_table.html' with table=interface_table %}
@@ -527,6 +530,11 @@
                         <div class="panel panel-default">
                         <div class="panel panel-default">
                             <div class="panel-heading">
                             <div class="panel-heading">
                                 <strong>Front Ports</strong>
                                 <strong>Front Ports</strong>
+                                <div class="pull-right noprint">
+                                    {% if request.user.is_authenticated %}
+                                        <button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#DeviceFrontPortTable_config" title="Configure table"><i class="fa fa-cog"></i> Configure</button>
+                                    {% endif %}
+                                </div>
                             </div>
                             </div>
                             {% include 'responsive_table.html' with table=frontport_table %}
                             {% include 'responsive_table.html' with table=frontport_table %}
                             <div class="panel-footer noprint">
                             <div class="panel-footer noprint">
@@ -564,6 +572,11 @@
                         <div class="panel panel-default">
                         <div class="panel panel-default">
                             <div class="panel-heading">
                             <div class="panel-heading">
                                 <strong>Rear Ports</strong>
                                 <strong>Rear Ports</strong>
+                                <div class="pull-right noprint">
+                                    {% if request.user.is_authenticated %}
+                                        <button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#DeviceRearPortTable_config" title="Configure table"><i class="fa fa-cog"></i> Configure</button>
+                                    {% endif %}
+                                </div>
                             </div>
                             </div>
                             {% include 'responsive_table.html' with table=rearport_table %}
                             {% include 'responsive_table.html' with table=rearport_table %}
                             <div class="panel-footer noprint">
                             <div class="panel-footer noprint">
@@ -601,6 +614,11 @@
                         <div class="panel panel-default">
                         <div class="panel panel-default">
                             <div class="panel-heading">
                             <div class="panel-heading">
                                 <strong>Console Ports</strong>
                                 <strong>Console Ports</strong>
+                                <div class="pull-right noprint">
+                                    {% if request.user.is_authenticated %}
+                                        <button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#DeviceConsolePortTable_config" title="Configure table"><i class="fa fa-cog"></i> Configure</button>
+                                    {% endif %}
+                                </div>
                             </div>
                             </div>
                             {% include 'responsive_table.html' with table=consoleport_table %}
                             {% include 'responsive_table.html' with table=consoleport_table %}
                             <div class="panel-footer noprint">
                             <div class="panel-footer noprint">
@@ -638,6 +656,11 @@
                         <div class="panel panel-default">
                         <div class="panel panel-default">
                             <div class="panel-heading">
                             <div class="panel-heading">
                                 <strong>Console Server Ports</strong>
                                 <strong>Console Server Ports</strong>
+                                <div class="pull-right noprint">
+                                    {% if request.user.is_authenticated %}
+                                        <button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#DeviceConsoleServerPortTable_config" title="Configure table"><i class="fa fa-cog"></i> Configure</button>
+                                    {% endif %}
+                                </div>
                             </div>
                             </div>
                             {% include 'responsive_table.html' with table=consoleserverport_table %}
                             {% include 'responsive_table.html' with table=consoleserverport_table %}
                             <div class="panel-footer noprint">
                             <div class="panel-footer noprint">
@@ -675,6 +698,11 @@
                         <div class="panel panel-default">
                         <div class="panel panel-default">
                             <div class="panel-heading">
                             <div class="panel-heading">
                                 <strong>Power Ports</strong>
                                 <strong>Power Ports</strong>
+                                <div class="pull-right noprint">
+                                    {% if request.user.is_authenticated %}
+                                        <button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#DevicePowerPortTable_config" title="Configure table"><i class="fa fa-cog"></i> Configure</button>
+                                    {% endif %}
+                                </div>
                             </div>
                             </div>
                             {% include 'responsive_table.html' with table=powerport_table %}
                             {% include 'responsive_table.html' with table=powerport_table %}
                             <div class="panel-footer noprint">
                             <div class="panel-footer noprint">
@@ -711,6 +739,11 @@
                         <div class="panel panel-default">
                         <div class="panel panel-default">
                             <div class="panel-heading">
                             <div class="panel-heading">
                                 <strong>Power Outlets</strong>
                                 <strong>Power Outlets</strong>
+                                <div class="pull-right noprint">
+                                    {% if request.user.is_authenticated %}
+                                        <button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#DevicePowerOutletTable_config" title="Configure table"><i class="fa fa-cog"></i> Configure</button>
+                                    {% endif %}
+                                </div>
                             </div>
                             </div>
                             {% include 'responsive_table.html' with table=poweroutlet_table %}
                             {% include 'responsive_table.html' with table=poweroutlet_table %}
                             <div class="panel-footer noprint">
                             <div class="panel-footer noprint">
@@ -748,6 +781,11 @@
                         <div class="panel panel-default">
                         <div class="panel panel-default">
                             <div class="panel-heading">
                             <div class="panel-heading">
                                 <strong>Device Bays</strong>
                                 <strong>Device Bays</strong>
+                                <div class="pull-right noprint">
+                                    {% if request.user.is_authenticated %}
+                                        <button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#DeviceDeviceBayTable_config" title="Configure table"><i class="fa fa-cog"></i> Configure</button>
+                                    {% endif %}
+                                </div>
                             </div>
                             </div>
                             {% include 'responsive_table.html' with table=devicebay_table %}
                             {% include 'responsive_table.html' with table=devicebay_table %}
                             <div class="panel-footer noprint">
                             <div class="panel-footer noprint">
@@ -779,6 +817,11 @@
                         <div class="panel panel-default">
                         <div class="panel panel-default">
                             <div class="panel-heading">
                             <div class="panel-heading">
                                 <strong>Inventory Items</strong>
                                 <strong>Inventory Items</strong>
+                                <div class="pull-right noprint">
+                                    {% if request.user.is_authenticated %}
+                                        <button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#DeviceInventoryItemTable_config" title="Configure table"><i class="fa fa-cog"></i> Configure</button>
+                                    {% endif %}
+                                </div>
                             </div>
                             </div>
                             {% include 'responsive_table.html' with table=inventoryitem_table %}
                             {% include 'responsive_table.html' with table=inventoryitem_table %}
                             <div class="panel-footer noprint">
                             <div class="panel-footer noprint">
@@ -811,6 +854,15 @@
         </div>
         </div>
     </div>
     </div>
 {% include 'secrets/inc/private_key_modal.html' %}
 {% include 'secrets/inc/private_key_modal.html' %}
+{% table_config_form interface_table %}
+{% table_config_form frontport_table %}
+{% table_config_form rearport_table %}
+{% table_config_form consoleport_table %}
+{% table_config_form consoleserverport_table %}
+{% table_config_form powerport_table %}
+{% table_config_form poweroutlet_table %}
+{% table_config_form devicebay_table %}
+{% table_config_form inventoryitem_table %}
 {% endblock %}
 {% endblock %}
 
 
 {% block javascript %}
 {% block javascript %}
@@ -864,4 +916,5 @@ $(".cable-toggle").click(function() {
 </script>
 </script>
 <script src="{% static 'js/interface_toggles.js' %}?v{{ settings.VERSION }}"></script>
 <script src="{% static 'js/interface_toggles.js' %}?v{{ settings.VERSION }}"></script>
 <script src="{% static 'js/secrets.js' %}?v{{ settings.VERSION }}"></script>
 <script src="{% static 'js/secrets.js' %}?v{{ settings.VERSION }}"></script>
+<script src="{% static 'js/tableconfig.js' %}?v{{ settings.VERSION }}"></script>
 {% endblock %}
 {% endblock %}

+ 2 - 4
netbox/templates/utilities/obj_list.html

@@ -7,7 +7,7 @@
 <div class="pull-right noprint">
 <div class="pull-right noprint">
     {% block buttons %}{% endblock %}
     {% block buttons %}{% endblock %}
     {% if request.user.is_authenticated and table_config_form %}
     {% if request.user.is_authenticated and table_config_form %}
-        <button type="button" class="btn btn-default" data-toggle="modal" data-target="#tableconfig" title="Configure table"><i class="fa fa-cog"></i> Configure</button>
+        <button type="button" class="btn btn-default" data-toggle="modal" data-target="#ObjectTable_config" title="Configure table"><i class="fa fa-cog"></i> Configure</button>
     {% endif %}
     {% endif %}
     {% if permissions.add and 'add' in action_buttons %}
     {% if permissions.add and 'add' in action_buttons %}
         {% add_button content_type.model_class|validated_viewname:"add" %}
         {% add_button content_type.model_class|validated_viewname:"add" %}
@@ -72,9 +72,6 @@
         {% endwith %}
         {% endwith %}
         {% include 'inc/paginator.html' with paginator=table.paginator page=table.page %}
         {% include 'inc/paginator.html' with paginator=table.paginator page=table.page %}
         <div class="clearfix"></div>
         <div class="clearfix"></div>
-        {% if table_config_form %}
-            {% include 'inc/table_config_form.html' %}
-        {% endif %}
     </div>
     </div>
     {% if filter_form %}
     {% if filter_form %}
         <div class="col-md-3 noprint">
         <div class="col-md-3 noprint">
@@ -83,6 +80,7 @@
         </div>
         </div>
     {% endif %}
     {% endif %}
 </div>
 </div>
+{% table_config_form table table_name="ObjectTable" %}
 {% endblock %}
 {% endblock %}
 
 
 {% block javascript %}
 {% block javascript %}

+ 1 - 1
netbox/templates/inc/table_config_form.html → netbox/templates/utilities/templatetags/table_config_form.html

@@ -1,5 +1,5 @@
 {% load form_helpers %}
 {% load form_helpers %}
-<div class="modal fade" tabindex="-1" id="tableconfig">
+<div class="modal fade" tabindex="-1" id="{{ table_name }}_config">
     <div class="modal-dialog">
     <div class="modal-dialog">
         <div class="modal-content">
         <div class="modal-content">
             <div class="modal-header">
             <div class="modal-header">

+ 9 - 0
netbox/utilities/templatetags/helpers.py

@@ -10,6 +10,7 @@ from django.utils.html import strip_tags
 from django.utils.safestring import mark_safe
 from django.utils.safestring import mark_safe
 from markdown import markdown
 from markdown import markdown
 
 
+from utilities.forms import TableConfigForm
 from utilities.utils import foreground_color
 from utilities.utils import foreground_color
 
 
 register = template.Library()
 register = template.Library()
@@ -261,3 +262,11 @@ def badge(value, show_empty=False):
         'value': value,
         'value': value,
         'show_empty': show_empty,
         'show_empty': show_empty,
     }
     }
+
+
+@register.inclusion_tag('utilities/templatetags/table_config_form.html')
+def table_config_form(table, table_name=None):
+    return {
+        'table_name': table_name or table.__class__.__name__,
+        'table_config_form': TableConfigForm(table=table),
+    }