def validate_select_field_data( field_data: ProfileFieldData) -> Dict[str, Dict[str, str]]: """ This function is used to validate the data sent to the server while creating/editing choices of the choice field in Organization settings. """ validator = check_dict_only([ ("text", check_required_string), ("order", check_required_string), ]) # To create an array of texts of each option distinct_field_names: Set[str] = set() for key, value in field_data.items(): if not key.strip(): raise ValidationError( _("'{item}' cannot be blank.").format(item="value")) valid_value = validator("field_data", value) assert value is valid_value # To justify the unchecked cast below distinct_field_names.add(valid_value["text"]) # To show error if the options are duplicate if len(field_data) != len(distinct_field_names): raise ValidationError(_("Field must not have duplicate choices.")) return cast(Dict[str, Dict[str, str]], field_data)
def validate_choice_field_data(field_data: ProfileFieldData) -> Dict[str, Dict[str, str]]: """ This function is used to validate the data sent to the server while creating/editing choices of the choice field in Organization settings. """ validator = check_dict_only([ ('text', check_required_string), ('order', check_required_string), ]) for key, value in field_data.items(): if not key.strip(): raise ValidationError(_("'{item}' cannot be blank.").format(item='value')) valid_value = validator('field_data', value) assert value is valid_value # To justify the unchecked cast below return cast(Dict[str, Dict[str, str]], field_data)
def validate_choice_field_data(field_data: ProfileFieldData) -> Optional[str]: """ This function is used to validate the data sent to the server while creating/editing choices of the choice field in Organization settings. """ validator = check_dict_only([ ('text', check_required_string), ('order', check_required_string), ]) for key, value in field_data.items(): if not key.strip(): return _("'{item}' cannot be blank.").format(item='value') error = validator('field_data', value) if error: return error return None
def validate_field_data(field_data: ProfileFieldData) -> Optional[str]: """ This function is used to validate the data sent to the server while creating/editing choices of the choice field in Organization settings. """ validator = check_dict_only([ ('text', check_required_string), ('order', check_required_string), ]) for key, value in field_data.items(): if not key.strip(): return _("'{item}' cannot be blank.").format(item='value') error = validator('field_data', value) if error: return error return None