mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 05:28:16 -06:00
14550 fix event rule action type
This commit is contained in:
parent
12b291e968
commit
36cf3e5e03
@ -308,9 +308,10 @@ class EventRuleForm(NetBoxModelForm):
|
|||||||
self.fields['action_choice'].choices = choices
|
self.fields['action_choice'].choices = choices
|
||||||
|
|
||||||
if self.instance.pk:
|
if self.instance.pk:
|
||||||
scriptmodule_id = self.instance.action_object_id
|
scriptmodule_id = get_field_value(self, 'action_object_id')
|
||||||
if self.instance.action_parameters:
|
action_parameters = get_field_value(self, 'action_parameters')
|
||||||
script_name = self.instance.action_parameters.get('script_name')
|
if action_parameters and scriptmodule_id:
|
||||||
|
script_name = action_parameters.get('script_name')
|
||||||
self.fields['action_choice'].initial = f'{scriptmodule_id}:{script_name}'
|
self.fields['action_choice'].initial = f'{scriptmodule_id}:{script_name}'
|
||||||
else:
|
else:
|
||||||
self.fields['action_choice'].inital = None
|
self.fields['action_choice'].inital = None
|
||||||
|
@ -416,6 +416,16 @@ class EventRuleEditView(generic.ObjectEditView):
|
|||||||
queryset = EventRule.objects.all()
|
queryset = EventRule.objects.all()
|
||||||
form = forms.EventRuleForm
|
form = forms.EventRuleForm
|
||||||
|
|
||||||
|
def get_initial_data(self, request):
|
||||||
|
initial_data = normalize_querydict(request.GET)
|
||||||
|
|
||||||
|
if is_htmx(request):
|
||||||
|
initial_data['action_object_type'] = None
|
||||||
|
initial_data['action_object_id'] = None
|
||||||
|
initial_data['action_parameters'] = None
|
||||||
|
|
||||||
|
return initial_data
|
||||||
|
|
||||||
|
|
||||||
@register_model_view(EventRule, 'delete')
|
@register_model_view(EventRule, 'delete')
|
||||||
class EventRuleDeleteView(generic.ObjectDeleteView):
|
class EventRuleDeleteView(generic.ObjectDeleteView):
|
||||||
|
@ -204,6 +204,9 @@ class ObjectEditView(GetReturnURLMixin, BaseObjectView):
|
|||||||
"""
|
"""
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
def get_initial_data(self, request):
|
||||||
|
return normalize_querydict(request.GET)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Request handlers
|
# Request handlers
|
||||||
#
|
#
|
||||||
@ -219,7 +222,8 @@ class ObjectEditView(GetReturnURLMixin, BaseObjectView):
|
|||||||
obj = self.alter_object(obj, request, args, kwargs)
|
obj = self.alter_object(obj, request, args, kwargs)
|
||||||
model = self.queryset.model
|
model = self.queryset.model
|
||||||
|
|
||||||
initial_data = normalize_querydict(request.GET)
|
initial_data = self.get_initial_data(request)
|
||||||
|
|
||||||
form = self.form(instance=obj, initial=initial_data)
|
form = self.form(instance=obj, initial=initial_data)
|
||||||
restrict_form_fields(form, request.user)
|
restrict_form_fields(form, request.user)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user