14132 fix JSON field issue

This commit is contained in:
Arthur 2023-11-17 11:28:08 -08:00
parent 1d7aace56e
commit 488f0c5427
2 changed files with 12 additions and 2 deletions

View File

@ -244,6 +244,14 @@ class EventRuleForm(NetBoxModelForm):
label=_('Action choice'), label=_('Action choice'),
choices=[] choices=[]
) )
conditions = JSONField(
required=False,
help_text=_('Enter conditions in <a href="https://json.org/">JSON</a> format.')
)
action_data = JSONField(
required=False,
help_text=_('Enter parameters to pass to the action in <a href="https://json.org/">JSON</a> format.')
)
fieldsets = ( fieldsets = (
(_('EventRule'), ('name', 'description', 'content_types', 'enabled', 'tags')), (_('EventRule'), ('name', 'description', 'content_types', 'enabled', 'tags')),
@ -268,8 +276,6 @@ class EventRuleForm(NetBoxModelForm):
'action_object_type': forms.HiddenInput, 'action_object_type': forms.HiddenInput,
'action_object_id': forms.HiddenInput, 'action_object_id': forms.HiddenInput,
'action_parameters': forms.HiddenInput, 'action_parameters': forms.HiddenInput,
'conditions': forms.Textarea(attrs={'class': 'font-monospace'}),
'action_data': forms.Textarea(attrs={'class': 'font-monospace'}),
} }
def get_script_choices(self): def get_script_choices(self):
@ -311,6 +317,8 @@ class EventRuleForm(NetBoxModelForm):
elif action_type == EventRuleActionChoices.SCRIPT: elif action_type == EventRuleActionChoices.SCRIPT:
self.get_script_choices() self.get_script_choices()
val = get_field_value(self, 'conditions')
def clean(self): def clean(self):
super().clean() super().clean()

View File

@ -101,6 +101,8 @@ class JSONField(_JSONField):
self.widget.attrs['class'] = 'font-monospace' self.widget.attrs['class'] = 'font-monospace'
def prepare_value(self, value): def prepare_value(self, value):
if value == '':
return value
if isinstance(value, InvalidJSONInput): if isinstance(value, InvalidJSONInput):
return value return value
if value is None: if value is None: