| 21 | |
| 22 | |
| 23 | class InputField(serializers.Serializer): |
| 24 | name = serializers.CharField(required=True, label=_('Variable Name')) |
| 25 | is_required = serializers.BooleanField(required=True, label=_("Is this field required")) |
| 26 | type = serializers.CharField(required=True, label=_("type"), validators=[ |
| 27 | validators.RegexValidator(regex=re.compile("^string|int|dict|array|float|boolean$"), |
| 28 | message=_("The field only supports string|int|dict|array|float"), code=500) |
| 29 | ]) |
| 30 | source = serializers.CharField(required=True, label=_("source"), validators=[ |
| 31 | validators.RegexValidator(regex=re.compile("^custom|reference$"), |
| 32 | message=_("The field only supports custom|reference"), code=500) |
| 33 | ]) |
| 34 | value = ObjectField(required=True, label=_("Variable Value"), model_type_list=[str, list]) |
| 35 | |
| 36 | def is_valid(self, *, raise_exception=False): |
| 37 | super().is_valid(raise_exception=True) |
| 38 | is_required = self.data.get('is_required') |
| 39 | if is_required and self.data.get('value') is None: |
| 40 | message = lazy_format(_('{field}, this field is required.'), field=self.data.get("name")) |
| 41 | raise AppApiException(500, message) |
| 42 | |
| 43 | |
| 44 | class FunctionNodeParamsSerializer(serializers.Serializer): |
no test coverage detected