mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-17 13:08:16 -06:00
14438 update init_script_choice in form
This commit is contained in:
parent
3182977a88
commit
8b54ff7e33
@ -297,19 +297,16 @@ class EventRuleForm(NetBoxModelForm):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def init_script_choice(self):
|
def init_script_choice(self):
|
||||||
choices = []
|
initial = None
|
||||||
for module in ScriptModule.objects.all():
|
|
||||||
script_list = []
|
|
||||||
for script in module.scripts.all().prefetch_related('scripts'):
|
|
||||||
name = f"{str(script.pk)}:{script.name}"
|
|
||||||
script_list.append((name, script.name))
|
|
||||||
if script_list:
|
|
||||||
choices.append((str(module), script_list))
|
|
||||||
self.fields['action_choice'].choices = choices
|
|
||||||
|
|
||||||
if self.instance.action_type == EventRuleActionChoices.SCRIPT:
|
if self.instance.action_type == EventRuleActionChoices.SCRIPT:
|
||||||
script = self.instance.action_object
|
script_id = get_field_value(self, 'action_object_id')
|
||||||
self.fields['action_choice'].initial = f'{script.id}:{script.name}'
|
initial = Script.objects.get(pk=script_id) if script_id else None
|
||||||
|
self.fields['action_choice'] = DynamicModelChoiceField(
|
||||||
|
label=_('Script'),
|
||||||
|
queryset=Script.objects.all(),
|
||||||
|
required=True,
|
||||||
|
initial=initial
|
||||||
|
)
|
||||||
|
|
||||||
def init_webhook_choice(self):
|
def init_webhook_choice(self):
|
||||||
initial = None
|
initial = None
|
||||||
@ -350,8 +347,7 @@ class EventRuleForm(NetBoxModelForm):
|
|||||||
Script,
|
Script,
|
||||||
for_concrete_model=False
|
for_concrete_model=False
|
||||||
)
|
)
|
||||||
script_id, script_name = action_choice.split(":", maxsplit=1)
|
self.cleaned_data['action_object_id'] = action_choice.id
|
||||||
self.cleaned_data['action_object_id'] = script_id
|
|
||||||
|
|
||||||
return self.cleaned_data
|
return self.cleaned_data
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user