move check to serializer
This commit is contained in:
parent
2ac85a3511
commit
f6cf81ea5a
|
|
@ -188,6 +188,16 @@ class ScriptInputSerializer(serializers.Serializer):
|
|||
if script and script.python_class:
|
||||
self.fields['notifications'].default = script.python_class.notifications_default
|
||||
|
||||
def validate_data(self, value):
|
||||
"""
|
||||
Validates that the script input is an object mapping variable names to values.
|
||||
"""
|
||||
if not isinstance(value, dict):
|
||||
raise serializers.ValidationError(
|
||||
_('Invalid data payload; expected an object mapping variable names to values.')
|
||||
)
|
||||
return value
|
||||
|
||||
def validate_schedule_at(self, value):
|
||||
"""
|
||||
Validates the specified schedule time for a script execution.
|
||||
|
|
|
|||
|
|
@ -409,11 +409,7 @@ class ScriptViewSet(ListModelMixin, RetrieveModelMixin, BaseViewSet):
|
|||
|
||||
validated = input_serializer.validated_data
|
||||
|
||||
payload = validated.get('data')
|
||||
if not isinstance(payload, dict):
|
||||
raise ValidationError(
|
||||
{'data': _('Invalid data payload; expected an object mapping variable names to values.')}
|
||||
)
|
||||
payload = validated['data']
|
||||
|
||||
# Guaranteed non-None by the is_executable check above
|
||||
script_class = script.python_class
|
||||
|
|
|
|||
Loading…
Reference in New Issue