mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 05:28:16 -06:00
Fix json string sent by render_script_data, and setups run_script to process the input data inside the script form
This commit is contained in:
parent
4de5046109
commit
1ed0980632
@ -177,7 +177,7 @@ class EventRule(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLogged
|
|||||||
Render Script Data, if defined. Otherwise, jump the context as a JSON object.
|
Render Script Data, if defined. Otherwise, jump the context as a JSON object.
|
||||||
"""
|
"""
|
||||||
if self.action_data:
|
if self.action_data:
|
||||||
return render_jinja2(str(self.action_data), context)
|
return render_jinja2(json.dumps(self.action_data), context)
|
||||||
else:
|
else:
|
||||||
return json.dumps(context, cls=JSONEncoder)
|
return json.dumps(context, cls=JSONEncoder)
|
||||||
|
|
||||||
|
@ -488,6 +488,12 @@ def run_script(data, job, request=None, commit=True, **kwargs):
|
|||||||
module = ScriptModule.objects.get(pk=job.object_id)
|
module = ScriptModule.objects.get(pk=job.object_id)
|
||||||
script = module.scripts.get(job.name)()
|
script = module.scripts.get(job.name)()
|
||||||
|
|
||||||
|
if isinstance(data, str):
|
||||||
|
data = json.loads(data)
|
||||||
|
form = script.as_form(data)
|
||||||
|
if form.is_valid():
|
||||||
|
data = form.cleaned_data
|
||||||
|
|
||||||
logger = logging.getLogger(f"netbox.scripts.{script.full_name}")
|
logger = logging.getLogger(f"netbox.scripts.{script.full_name}")
|
||||||
logger.info(f"Running script (commit={commit})")
|
logger.info(f"Running script (commit={commit})")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user