Skip to content

Commit 15ce08d

Browse files
[ui] Attribute: Add helpers to create success and error response in validators
1 parent 56b75a3 commit 15ce08d

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
""" Interface for an attribute validation
@@ -41,9 +44,9 @@ class NotEmptyValidator(AttributeValidator):
4144
def __call__(self, node: "Node", attribute: "Attribute") -> tuple[bool, list[str]]:
4245

4346
if attribute.value is None or attribute.value == "":
44-
return (False, ["Empty value are not allowed"])
47+
return error("Empty value are not allowed")
4548

46-
return SuccessResponse
49+
return success()
4750

4851

4952
class RangeValidator(AttributeValidator):
@@ -57,7 +60,7 @@ def __init__(self, min, max):
5760
def __call__(self, node:"Node", attribute: "Attribute") -> tuple[bool, list[str]]:
5861

5962
if attribute.value < self._min or attribute.value > self._max:
60-
return (False, [f"Value should be greater than {self._min} and less than {self._max}",
61-
f"({self._min} < {attribute.value} < {self._max})"])
63+
return error(f"Value should be greater than {self._min} and less than {self._max}",
64+
f"({self._min} < {attribute.value} < {self._max})")
6265

63-
return SuccessResponse
66+
return success()

0 commit comments

Comments
 (0)