From 9c079ead4c0bc9706b5b6ac50fdf1b45a5a0db11 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 14 Aug 2019 10:18:25 -0400 Subject: [PATCH] Fix notice when form does not require user input --- netbox/extras/forms.py | 7 +++++++ netbox/templates/extras/script.html | 10 ++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/netbox/extras/forms.py b/netbox/extras/forms.py index 32ffc1396..5432e34be 100644 --- a/netbox/extras/forms.py +++ b/netbox/extras/forms.py @@ -404,3 +404,10 @@ class ScriptForm(BootstrapMixin, forms.Form): # Move _commit to the end of the form self.fields.move_to_end('_commit', True) + + @property + def requires_input(self): + """ + A boolean indicating whether the form requires user input (ignore the _commit field). + """ + return bool(len(self.fields) > 1) diff --git a/netbox/templates/extras/script.html b/netbox/templates/extras/script.html index c2b9bd205..06b2dfb15 100644 --- a/netbox/templates/extras/script.html +++ b/netbox/templates/extras/script.html @@ -74,11 +74,13 @@ {% endif %}
{% csrf_token %} - {% if form %} - {% render_form form %} - {% else %} -

This script does not require any input to run.

+ {% if not form.requires_input %} +
+ + This script does not require any input to run. +
{% endif %} + {% render_form form %}
Cancel