Преглед на файлове

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

Jeremy Stretch преди 6 години
родител
ревизия
54227ca9c7
променени са 3 файла, в които са добавени 4 реда и са изтрити 3 реда
  1. 1 0
      docs/release-notes/version-2.6.md
  2. 2 2
      netbox/extras/scripts.py
  3. 1 1
      netbox/extras/views.py

+ 1 - 0
docs/release-notes/version-2.6.md

@@ -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
 

+ 2 - 2
netbox/extras/scripts.py

@@ -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
 

+ 1 - 1
netbox/extras/views.py

@@ -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,