1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Closes #8368: Enable controlling the order of custom script form fields with field_order

This commit is contained in:
jeremystretch
2022-01-18 16:01:40 -05:00
parent 1f2d4fd2b3
commit 69eb6b11d0
3 changed files with 16 additions and 2 deletions

View File

@@ -296,12 +296,21 @@ class BaseScript:
@classmethod
def _get_vars(cls):
vars = OrderedDict()
vars = {}
for name, attr in cls.__dict__.items():
if name not in vars and issubclass(attr.__class__, ScriptVariable):
vars[name] = attr
return vars
# Order variables according to field_order
field_order = getattr(cls.Meta, 'field_order', None)
if not field_order:
return vars
ordered_vars = {
field: vars.pop(field) for field in field_order if field in vars
}
ordered_vars.update(vars)
return ordered_vars
def run(self, data, commit):
raise NotImplementedError("The script must define a run() method.")