-
A recent use case I have stumbled upon: say i would like to design a custom script to edit some parts of a device Config Context in a friendly form. Obviously I can do a "set" script where form input data replaces current data, but I can't find a way to query device data from script url (e.g. ...?device_id=666) before the form is displayed in order to populate vars with current data before user edit. Tried Script Anyone has an idea, or is it a new feature request? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
I don't know if this helps and I haven't thought this through or tried it but can you use some of the api endpoints from the client side in the way that the various filter drop-down lists are populated to select and fetch the device info using javascript to load into the form elements, rather than having it on the python server side when the page is generated?
—
Mark Tinberg ***@***.***>
Division of Information Technology-Network Services
University of Wisconsin-Madison
…________________________________
From: bistraque ***@***.***>
Sent: Thursday, February 3, 2022 11:18 AM
To: netbox-community/netbox ***@***.***>
Cc: Subscribed ***@***.***>
Subject: [netbox-community/netbox] Populating custom script variables (Discussion #8542)
A recent use case I have stumbled upon: say i would like to design a custom script to edit some parts of a device Config Context in a friendly form. Obviously I can do a "set" script where form input data replaces current data, but I can't find a way to query device data from script url (e.g. ...?device_id=666) before the form is displayed in order to populate vars with current data before user edit.
Tried Script __init__ override but with no luck.
Anyone has an idea, or is it a new feature request?
—
Reply to this email directly, view it on GitHub<#8542>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAS7UMZW2V2DU4ACE4XCA33UZK2HNANCNFSM5NPRCONQ>.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
So to clarify the question: are you trying to get access to the query URL which was used when the script was invoked? e.g.
displays the script form, and you want access to "foo=bar" inside your script when the user presses the "Run Script" button? In principle I think it could be made to work because I can see the POST goes back to the same URL, including the same query string. But I think Netbox would have to be extended to capture this and pass it to the script, which I believe these days runs as a background task - hence it's not directly connected to the web request. |
Beta Was this translation helpful? Give feedback.
-
For those interested, I found a solution by overiding Script
This method will be called twice: for GET where |
Beta Was this translation helpful? Give feedback.
For those interested, I found a solution by overiding Script
as_form()
method. Here is the logic:This method will be called twice: for GET where
data
is None andinitial
contains query params, and for POST wheredata
contains final form data.