Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

14550 fix EventRule HTMX change of action_type #14566

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions netbox/extras/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,13 @@ def init_script_choice(self):
self.fields['action_choice'].choices = choices

if self.instance.pk:
scriptmodule_id = self.instance.action_object_id
script_name = self.instance.action_parameters.get('script_name')
self.fields['action_choice'].initial = f'{scriptmodule_id}:{script_name}'
print(self.fields['action_choice'].initial)
scriptmodule_id = get_field_value(self, 'action_object_id')
action_parameters = get_field_value(self, 'action_parameters')
if action_parameters and scriptmodule_id:
script_name = action_parameters.get('script_name')
self.fields['action_choice'].initial = f'{scriptmodule_id}:{script_name}'
else:
self.fields['action_choice'].inital = None

def init_webhook_choice(self):
initial = None
Expand Down
10 changes: 10 additions & 0 deletions netbox/extras/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,16 @@ class EventRuleEditView(generic.ObjectEditView):
queryset = EventRule.objects.all()
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')
class EventRuleDeleteView(generic.ObjectDeleteView):
Expand Down
6 changes: 5 additions & 1 deletion netbox/netbox/views/generic/object_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ def get_extra_addanother_params(self, request):
"""
return {}

def get_initial_data(self, request):
return normalize_querydict(request.GET)

#
# Request handlers
#
Expand All @@ -219,7 +222,8 @@ def get(self, request, *args, **kwargs):
obj = self.alter_object(obj, request, args, kwargs)
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)
restrict_form_fields(form, request.user)

Expand Down