From 6ea5ee3e0eecda45f72d4dbe36352f49ab43202b Mon Sep 17 00:00:00 2001 From: candifloss Date: Sun, 9 Mar 2025 22:28:14 +0530 Subject: [PATCH] Updated config validation of 'compareto' --- functions/validate_config.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/functions/validate_config.py b/functions/validate_config.py index f60203b..09e7fc6 100644 --- a/functions/validate_config.py +++ b/functions/validate_config.py @@ -1,7 +1,14 @@ from typing import List 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: """ @@ -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." for cmp, ref_attr in attrib.compareto: - if cmp not in VALID_OPERATORS: - return f"Invalid comparison operator '{cmp}' for attribute '{attrib.attrib_name}'." + if cmp not in VALID_COMPARISONS[attrib.html_input_type]: + 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: 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" \ No newline at end of file