Introduce table_config_form template tag to simplify form generation

This commit is contained in:
Jeremy Stretch 2020-10-23 16:47:53 -04:00
parent ff3d0b72b9
commit ce2210b7bc
4 changed files with 66 additions and 6 deletions

View File

@ -485,8 +485,11 @@
<div class="panel panel-default">
<div class="panel-heading">
<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" />
{% 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>
{% include 'responsive_table.html' with table=interface_table %}
@ -527,6 +530,11 @@
<div class="panel panel-default">
<div class="panel-heading">
<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>
{% include 'responsive_table.html' with table=frontport_table %}
<div class="panel-footer noprint">
@ -564,6 +572,11 @@
<div class="panel panel-default">
<div class="panel-heading">
<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>
{% include 'responsive_table.html' with table=rearport_table %}
<div class="panel-footer noprint">
@ -601,6 +614,11 @@
<div class="panel panel-default">
<div class="panel-heading">
<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>
{% include 'responsive_table.html' with table=consoleport_table %}
<div class="panel-footer noprint">
@ -638,6 +656,11 @@
<div class="panel panel-default">
<div class="panel-heading">
<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>
{% include 'responsive_table.html' with table=consoleserverport_table %}
<div class="panel-footer noprint">
@ -675,6 +698,11 @@
<div class="panel panel-default">
<div class="panel-heading">
<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>
{% include 'responsive_table.html' with table=powerport_table %}
<div class="panel-footer noprint">
@ -711,6 +739,11 @@
<div class="panel panel-default">
<div class="panel-heading">
<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>
{% include 'responsive_table.html' with table=poweroutlet_table %}
<div class="panel-footer noprint">
@ -748,6 +781,11 @@
<div class="panel panel-default">
<div class="panel-heading">
<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>
{% include 'responsive_table.html' with table=devicebay_table %}
<div class="panel-footer noprint">
@ -779,6 +817,11 @@
<div class="panel panel-default">
<div class="panel-heading">
<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>
{% include 'responsive_table.html' with table=inventoryitem_table %}
<div class="panel-footer noprint">
@ -811,6 +854,15 @@
</div>
</div>
{% 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 %}
{% block javascript %}
@ -864,4 +916,5 @@ $(".cable-toggle").click(function() {
</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/tableconfig.js' %}?v{{ settings.VERSION }}"></script>
{% endblock %}

View File

@ -7,7 +7,7 @@
<div class="pull-right noprint">
{% block buttons %}{% endblock %}
{% 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 %}
{% if permissions.add and 'add' in action_buttons %}
{% add_button content_type.model_class|validated_viewname:"add" %}
@ -72,9 +72,6 @@
{% endwith %}
{% include 'inc/paginator.html' with paginator=table.paginator page=table.page %}
<div class="clearfix"></div>
{% if table_config_form %}
{% include 'inc/table_config_form.html' %}
{% endif %}
</div>
{% if filter_form %}
<div class="col-md-3 noprint">
@ -83,6 +80,7 @@
</div>
{% endif %}
</div>
{% table_config_form table table_name="ObjectTable" %}
{% endblock %}
{% block javascript %}

View File

@ -1,5 +1,5 @@
{% 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-content">
<div class="modal-header">

View File

@ -10,6 +10,7 @@ from django.utils.html import strip_tags
from django.utils.safestring import mark_safe
from markdown import markdown
from utilities.forms import TableConfigForm
from utilities.utils import foreground_color
register = template.Library()
@ -261,3 +262,11 @@ def badge(value, show_empty=False):
'value': value,
'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),
}