Stripping leading/trailing whitespace from input strings.

This commit is contained in:
Marat Fayzullin 2024-10-29 23:26:44 -04:00
parent 993195e213
commit 21832b8d70
2 changed files with 4 additions and 3 deletions

View File

@ -30,14 +30,15 @@ class TextConverter(Converter):
Converter class for text inputs Converter class for text inputs
Does nothing more than to prevent the special python value "None" from appearing in the form Does nothing more than to prevent the special python value "None" from appearing in the form
The string "None" should pass The string "None" should pass
Strips leading and trailing whitespace
""" """
def convert_to_form(self, value): def convert_to_form(self, value):
if value is None: if value is None:
return "" return ""
return value return str(value)
def convert_from_form(self, value): def convert_from_form(self, value):
return value return str(value).strip()
class OptionalConverter(Converter): class OptionalConverter(Converter):

View File

@ -11,7 +11,7 @@ class Validator(ABC):
class RequiredValidator(Validator): class RequiredValidator(Validator):
def validate(self, key, value) -> None: def validate(self, key, value) -> None:
if value is None or value == "": if value is None or value.strip() == "":
raise ValidationError(key, "Field is required") raise ValidationError(key, "Field is required")