Skip to content

Commit 404056d

Browse files
[ui] Attribute: Add helpers to create success and error response in validators
1 parent 59c4e40 commit 404056d

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

meshroom/core/desc/validators.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
from meshroom.core.node import Node
66

77

8-
SuccessResponse = (True, [])
8+
def success() -> tuple[bool, list[str]]:
9+
return (True, [])
910

11+
def error(*messages: str) -> tuple[bool, list[str]]:
12+
return (False, messages)
1013

1114
class AttributeValidator(object):
1215

@@ -18,9 +21,9 @@ class NotEmptyValidator(AttributeValidator):
1821
def __call__(self, node: "Node", attribute: "Attribute") -> tuple[bool, list[str]]:
1922

2023
if attribute.value is None or attribute.value == "":
21-
return (False, ["Empty value are not allowed"])
24+
return error("Empty value are not allowed")
2225

23-
return SuccessResponse
26+
return success()
2427

2528

2629
class RangeValidator(AttributeValidator):
@@ -32,7 +35,7 @@ def __init__(self, min, max):
3235
def __call__(self, node:"Node", attribute: "Attribute") -> tuple[bool, list[str]]:
3336

3437
if attribute.value < self._min or attribute.value > self._max:
35-
return (False, [f"Value should be greater than {self._min} and less than {self._max}",
36-
f"({self._min} < {attribute.value} < {self._max})"])
38+
return error(f"Value should be greater than {self._min} and less than {self._max}",
39+
f"({self._min} < {attribute.value} < {self._max})")
3740

38-
return SuccessResponse
41+
return success()

0 commit comments

Comments
 (0)