Updated config validation of 'compareto'
This commit is contained in:
parent
ae8e19f8a1
commit
6ea5ee3e0e
@ -1,7 +1,14 @@
|
|||||||
from typing import List
|
from typing import List
|
||||||
from definitions.attribute import Attribute
|
from definitions.attribute import Attribute
|
||||||
|
|
||||||
VALID_OPERATORS = {"lt", "gt", "le", "ge", "eq"}
|
#VALID_OPERATORS = {"lt", "gt", "le", "ge", "eq", "ne"} # <, >, <=, >=, ==, !=
|
||||||
|
|
||||||
|
VALID_COMPARISONS = {
|
||||||
|
"number": {"lt", "gt", "le", "ge", "eq", "ne"}, # <, >, <=, >=, ==, !=
|
||||||
|
"text": {"lt", "st", "eq", "ne"}, # longer than, shorter than, eq, or not eq, to the ref attrib
|
||||||
|
"date": {"lt", "gt", "le", "ge", "eq", "ne"}, # <, >, <=, >=, ==, !=
|
||||||
|
"select": {"eq", "ne"} # eq, or not eq, to the ref attrib
|
||||||
|
}
|
||||||
|
|
||||||
def validate_config(item_attributes: List[Attribute]) -> str:
|
def validate_config(item_attributes: List[Attribute]) -> str:
|
||||||
"""
|
"""
|
||||||
@ -31,9 +38,11 @@ def validate_config(item_attributes: List[Attribute]) -> str:
|
|||||||
):
|
):
|
||||||
return f"Invalid comparison format for attribute '{attrib.attrib_name}'. Expected a list of tuples."
|
return f"Invalid comparison format for attribute '{attrib.attrib_name}'. Expected a list of tuples."
|
||||||
for cmp, ref_attr in attrib.compareto:
|
for cmp, ref_attr in attrib.compareto:
|
||||||
if cmp not in VALID_OPERATORS:
|
if cmp not in VALID_COMPARISONS[attrib.html_input_type]:
|
||||||
return f"Invalid comparison operator '{cmp}' for attribute '{attrib.attrib_name}'."
|
return f"Invalid comparison '{cmp}' for attribute '{attrib.attrib_name}'. Allowed operators are: {VALID_COMPARISONS[attrib.html_input_type]}"
|
||||||
if ref_attr not in attrib_name_set:
|
if ref_attr not in attrib_name_set:
|
||||||
return f"Invalid reference attribute '{ref_attr}' for comparison in attribute '{attrib.attrib_name}'."
|
return f"Invalid reference attribute '{ref_attr}' for comparison in attribute '{attrib.attrib_name}'."
|
||||||
|
if ref_attr.html_input_type != attrib.html_input_type:
|
||||||
|
return f"Invalid comparison of '{attrib}' & '{ref_attr}' - must be of the same type, {attrib.html_input_type}."
|
||||||
|
|
||||||
return "Ok"
|
return "Ok"
|
Loading…
Reference in New Issue
Block a user