From 82a0240d2e1f48e5f5ca9fb79df0d0683397615f Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Wed, 29 Dec 2021 10:26:42 -0500 Subject: [PATCH] Closes #8182: Introduce checkmark template tag --- netbox/templates/dcim/devicerole.html | 8 +--- netbox/templates/dcim/devicetype.html | 8 +--- netbox/templates/dcim/interface.html | 16 +------- netbox/templates/dcim/virtualchassis.html | 2 +- netbox/templates/extras/customfield.html | 8 +--- netbox/templates/extras/customlink.html | 8 +--- netbox/templates/extras/exporttemplate.html | 8 +--- netbox/templates/extras/webhook.html | 40 +++---------------- .../templates/generic/object_bulk_import.html | 2 +- .../templates/inc/panels/custom_fields.html | 4 +- netbox/templates/ipam/prefix.html | 8 +--- netbox/templates/ipam/rir.html | 8 +--- netbox/templates/ipam/vrf.html | 8 +--- netbox/templates/users/profile.html | 16 +------- .../templates/helpers/checkmark.html | 5 +++ netbox/utilities/templatetags/helpers.py | 17 ++++++++ 16 files changed, 43 insertions(+), 123 deletions(-) create mode 100644 netbox/utilities/templates/helpers/checkmark.html diff --git a/netbox/templates/dcim/devicerole.html b/netbox/templates/dcim/devicerole.html index 4db2d3ad8..288101c08 100644 --- a/netbox/templates/dcim/devicerole.html +++ b/netbox/templates/dcim/devicerole.html @@ -40,13 +40,7 @@ VM Role - - {% if object.vm_role %} - - {% else %} - - {% endif %} - + {% checkmark object.vm_role %} Devices diff --git a/netbox/templates/dcim/devicetype.html b/netbox/templates/dcim/devicetype.html index 21a04e7d0..4b9dc8db7 100644 --- a/netbox/templates/dcim/devicetype.html +++ b/netbox/templates/dcim/devicetype.html @@ -33,13 +33,7 @@ Full Depth - - {% if object.is_full_depth %} - - {% else %} - - {% endif %} - + {% checkmark object.is_full_depth %} Parent/Child diff --git a/netbox/templates/dcim/interface.html b/netbox/templates/dcim/interface.html index bd0569c39..5eaa99c3f 100644 --- a/netbox/templates/dcim/interface.html +++ b/netbox/templates/dcim/interface.html @@ -48,23 +48,11 @@ Enabled - - {% if object.enabled %} - - {% else %} - - {% endif %} - + {% checkmark object.enabled %} Management Only - - {% if object.mgmt_only %} - - {% else %} - - {% endif %} - + {% checkmark object.mgmt_only %} Parent diff --git a/netbox/templates/dcim/virtualchassis.html b/netbox/templates/dcim/virtualchassis.html index eadf1645d..2e1344f71 100644 --- a/netbox/templates/dcim/virtualchassis.html +++ b/netbox/templates/dcim/virtualchassis.html @@ -65,7 +65,7 @@ {% if object.master == vc_member %} - + {% checkmark True %} {% endif %} diff --git a/netbox/templates/extras/customfield.html b/netbox/templates/extras/customfield.html index bf79059b8..9be7a485a 100644 --- a/netbox/templates/extras/customfield.html +++ b/netbox/templates/extras/customfield.html @@ -29,13 +29,7 @@ Required - - {% if object.required %} - - {% else %} - - {% endif %} - + {% checkmark object.required %} Weight diff --git a/netbox/templates/extras/customlink.html b/netbox/templates/extras/customlink.html index 42b2f6118..ebf50882c 100644 --- a/netbox/templates/extras/customlink.html +++ b/netbox/templates/extras/customlink.html @@ -33,13 +33,7 @@ New Window - - {% if object.new_window %} - - {% else %} - - {% endif %} - + {% checkmark object.new_window %} diff --git a/netbox/templates/extras/exporttemplate.html b/netbox/templates/extras/exporttemplate.html index 07b98ee93..912702b86 100644 --- a/netbox/templates/extras/exporttemplate.html +++ b/netbox/templates/extras/exporttemplate.html @@ -40,13 +40,7 @@ Attachment - - {% if object.as_attachment %} - - {% else %} - - {% endif %} - + {% checkmark object.as_attachment %} diff --git a/netbox/templates/extras/webhook.html b/netbox/templates/extras/webhook.html index ab53c56a2..6891930bc 100644 --- a/netbox/templates/extras/webhook.html +++ b/netbox/templates/extras/webhook.html @@ -17,13 +17,7 @@ Enabled - - {% if object.enabled %} - - {% else %} - - {% endif %} - + {% checkmark object.enabled %} @@ -36,33 +30,15 @@ - + - + - +
Create - {% if object.type_create %} - - {% else %} - - {% endif %} - {% checkmark object.type_create %}
Update - {% if object.type_update %} - - {% else %} - - {% endif %} - {% checkmark object.type_update %}
Delete - {% if object.type_delete %} - - {% else %} - - {% endif %} - {% checkmark object.type_delete %}
@@ -100,13 +76,7 @@ - + diff --git a/netbox/templates/generic/object_bulk_import.html b/netbox/templates/generic/object_bulk_import.html index 2d5957268..26ab2edf2 100644 --- a/netbox/templates/generic/object_bulk_import.html +++ b/netbox/templates/generic/object_bulk_import.html @@ -66,7 +66,7 @@ - +
SSL Verification - {% if object.ssl_verification %} - - {% else %} - - {% endif %} - {% checkmark object.ssl_verification %}
CA File Path {% if field.required %} - + {% checkmark True true="Required" %} {% else %} {% endif %} diff --git a/netbox/templates/inc/panels/custom_fields.html b/netbox/templates/inc/panels/custom_fields.html index b979cc073..b48a43f1c 100644 --- a/netbox/templates/inc/panels/custom_fields.html +++ b/netbox/templates/inc/panels/custom_fields.html @@ -15,9 +15,9 @@ {% if field.type == 'longtext' and value %} {{ value|render_markdown }} {% elif field.type == 'boolean' and value == True %} - + {% checkmark value true="True" %} {% elif field.type == 'boolean' and value == False %} - + {% checkmark value false="False" %} {% elif field.type == 'url' and value %} {{ value|truncatechars:70 }} {% elif field.type == 'json' and value %} diff --git a/netbox/templates/ipam/prefix.html b/netbox/templates/ipam/prefix.html index c7c0a441e..c3d3bdedd 100644 --- a/netbox/templates/ipam/prefix.html +++ b/netbox/templates/ipam/prefix.html @@ -94,13 +94,7 @@
Is a pool - {% if object.is_pool %} - - {% else %} - - {% endif %} - {% checkmark object.is_pool %}
diff --git a/netbox/templates/ipam/rir.html b/netbox/templates/ipam/rir.html index 0c38855b5..555fed1de 100644 --- a/netbox/templates/ipam/rir.html +++ b/netbox/templates/ipam/rir.html @@ -30,13 +30,7 @@ Private - - {% if object.is_private %} - - {% else %} - - {% endif %} - + {% checkmark object.is_private %} Aggregates diff --git a/netbox/templates/ipam/vrf.html b/netbox/templates/ipam/vrf.html index 349fe20d3..ae4f65887 100644 --- a/netbox/templates/ipam/vrf.html +++ b/netbox/templates/ipam/vrf.html @@ -30,13 +30,7 @@ Unique IP Space - - {% if object.enforce_unique %} - - {% else %} - - {% endif %} - + {% checkmark object.enforce_unique %} Description diff --git a/netbox/templates/users/profile.html b/netbox/templates/users/profile.html index 460ca63e7..112603126 100644 --- a/netbox/templates/users/profile.html +++ b/netbox/templates/users/profile.html @@ -35,23 +35,11 @@ Superuser - - {% if request.user.is_superuser %} - - {% else %} - - {% endif %} - + {% checkmark request.user.is_superuser %} Admin Access - - {% if request.user.is_staff %} - - {% else %} - - {% endif %} - + {% checkmark request.user.is_staff %} diff --git a/netbox/utilities/templates/helpers/checkmark.html b/netbox/utilities/templates/helpers/checkmark.html new file mode 100644 index 000000000..e4eacae01 --- /dev/null +++ b/netbox/utilities/templates/helpers/checkmark.html @@ -0,0 +1,5 @@ +{% if value %} + +{% elif show_false %} + +{% endif %} diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py index c054785fc..0e45cb581 100644 --- a/netbox/utilities/templatetags/helpers.py +++ b/netbox/utilities/templatetags/helpers.py @@ -426,6 +426,23 @@ def badge(value, bg_class='secondary', show_empty=False): } +@register.inclusion_tag('helpers/checkmark.html') +def checkmark(value, show_false=True, true='Yes', false='No'): + """ + Display either a green checkmark or red X to indicate a boolean value. + + :param show_false: Display a red X if the value is False + :param true: Text label for true value + :param false: Text label for false value + """ + return { + 'value': bool(value), + 'show_false': show_false, + 'true_label': true, + 'false_label': false, + } + + @register.inclusion_tag('helpers/table_config_form.html') def table_config_form(table, table_name=None): return {