mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 01:41:22 -06:00
Fixes #3851: Allow passing initial data to custom script forms
This commit is contained in:
parent
b36d0ca3fc
commit
54227ca9c7
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user