Fixes #3851: Allow passing initial data to custom script forms

This commit is contained in:
Jeremy Stretch 2020-01-09 09:41:10 -05:00
parent b36d0ca3fc
commit 54227ca9c7
3 changed files with 4 additions and 3 deletions

View File

@ -4,6 +4,7 @@
* [#2050](https://github.com/netbox-community/netbox/issues/2050) - Preview image attachments when hovering the link
* [#3187](https://github.com/netbox-community/netbox/issues/3187) - Add rack selection field to rack elevations
* [#3851](https://github.com/netbox-community/netbox/issues/3851) - Allow passing initial data to custom script forms
## Bug Fixes

View File

@ -263,12 +263,12 @@ class BaseScript:
def run(self, data):
raise NotImplementedError("The script must define a run() method.")
def as_form(self, data=None, files=None):
def as_form(self, data=None, files=None, initial=None):
"""
Return a Django form suitable for populating the context data required to run this Script.
"""
vars = self._get_vars()
form = ScriptForm(vars, data, files, commit_default=getattr(self.Meta, 'commit_default', True))
form = ScriptForm(vars, data, files, initial=initial, commit_default=getattr(self.Meta, 'commit_default', True))
return form

View File

@ -392,7 +392,7 @@ class ScriptView(PermissionRequiredMixin, View):
def get(self, request, module, name):
script = self._get_script(module, name)
form = script.as_form()
form = script.as_form(initial=request.GET)
return render(request, 'extras/script.html', {
'module': module,