Skip to content

Commit

Permalink
Fix type of validations
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffersonBledsoe committed Jan 18, 2024
1 parent 2899a93 commit e98dd67
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from zope.interface import implementer


# TODO: Tidy up code structure so we don't need to be a definition
@implementer(IValidator)
class CharactersValidator:
def __init__(self, name, title="", description="", characters=0, _internal_type=""):
Expand All @@ -12,21 +11,22 @@ def __init__(self, name, title="", description="", characters=0, _internal_type=
self.characters = characters
self._internal_type = _internal_type

@property
def settings(self):
return vars(self)

def __call__(self, value="", *args, **kwargs):
characters = (
int(self.characters)
if isinstance(self.characters, str)
else self.characters
)
if self._internal_type == "max":
if not value or len(value) > self.characters:
if not value or len(value) > characters:
# TODO: i18n
msg = f"Validation failed({self.name}): is more than {self.characters}"
msg = f"Validation failed({self.name}): is more than {characters} characters long"
return msg
elif self._internal_type == "min":
if not value or len(value) < self.characters:
if not value or len(value) < characters:
# TODO: i18n
msg = (
f"Validation failed({self.name}): is less than {self.characters}",
f"Validation failed({self.name}): is less than {characters} characters long",
)
return msg
else:
Expand Down

0 comments on commit e98dd67

Please sign in to comment.