@@ -269,8 +269,7 @@ class EventRuleForm(NetBoxModelForm):
269
269
(_ ('Events' ), ('type_create' , 'type_update' , 'type_delete' , 'type_job_start' , 'type_job_end' )),
270
270
(_ ('Conditions' ), ('conditions' ,)),
271
271
(_ ('Action' ), (
272
- 'action_type' , 'action_choice' , 'action_parameters' , 'action_object_type' , 'action_object_id' ,
273
- 'action_data' ,
272
+ 'action_type' , 'action_choice' , 'action_object_type' , 'action_object_id' , 'action_data' ,
274
273
)),
275
274
)
276
275
@@ -279,7 +278,7 @@ class Meta:
279
278
fields = (
280
279
'content_types' , 'name' , 'description' , 'type_create' , 'type_update' , 'type_delete' , 'type_job_start' ,
281
280
'type_job_end' , 'enabled' , 'conditions' , 'action_type' , 'action_object_type' , 'action_object_id' ,
282
- 'action_parameters' , ' action_data' , 'comments' , 'tags'
281
+ 'action_data' , 'comments' , 'tags'
283
282
)
284
283
labels = {
285
284
'type_create' : _ ('Creations' ),
@@ -293,7 +292,6 @@ class Meta:
293
292
'action_type' : HTMXSelect (),
294
293
'action_object_type' : forms .HiddenInput ,
295
294
'action_object_id' : forms .HiddenInput ,
296
- 'action_parameters' : forms .HiddenInput ,
297
295
}
298
296
299
297
def init_script_choice (self ):
@@ -307,16 +305,16 @@ def init_script_choice(self):
307
305
choices .append ((str (module ), scripts ))
308
306
self .fields ['action_choice' ].choices = choices
309
307
310
- if self .instance .pk :
308
+ if self .instance .action_type == EventRuleActionChoices . SCRIPT and self . instance . action_parameters :
311
309
scriptmodule_id = self .instance .action_object_id
312
310
script_name = self .instance .action_parameters .get ('script_name' )
313
311
self .fields ['action_choice' ].initial = f'{ scriptmodule_id } :{ script_name } '
314
- print (self .fields ['action_choice' ].initial )
315
312
316
313
def init_webhook_choice (self ):
317
314
initial = None
318
- if self .fields ['action_object_type' ] and get_field_value (self , 'action_object_id' ):
319
- initial = Webhook .objects .get (pk = get_field_value (self , 'action_object_id' ))
315
+ if self .instance .action_type == EventRuleActionChoices .WEBHOOK :
316
+ webhook_id = get_field_value (self , 'action_object_id' )
317
+ initial = Webhook .objects .get (pk = webhook_id ) if webhook_id else None
320
318
self .fields ['action_choice' ] = DynamicModelChoiceField (
321
319
label = _ ('Webhook' ),
322
320
queryset = Webhook .objects .all (),
@@ -353,11 +351,20 @@ def clean(self):
353
351
)
354
352
module_id , script_name = action_choice .split (":" , maxsplit = 1 )
355
353
self .cleaned_data ['action_object_id' ] = module_id
356
- self .cleaned_data ['action_parameters' ] = {
354
+
355
+ return self .cleaned_data
356
+
357
+ def save (self , * args , ** kwargs ):
358
+ # Set action_parameters on the instance
359
+ if self .cleaned_data ['action_type' ] == EventRuleActionChoices .SCRIPT :
360
+ module_id , script_name = self .cleaned_data .get ('action_choice' ).split (":" , maxsplit = 1 )
361
+ self .instance .action_parameters = {
357
362
'script_name' : script_name ,
358
363
}
364
+ else :
365
+ self .instance .action_parameters = None
359
366
360
- return self . cleaned_data
367
+ return super (). save ( * args , ** kwargs )
361
368
362
369
363
370
class TagForm (BootstrapMixin , forms .ModelForm ):
0 commit comments