Skip to content

Commit

Permalink
[#3607] Switch to a validator mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Jan 9, 2024
1 parent 0817624 commit becb03f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/openforms/contrib/kvk/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class KVKBranchNumberValidator(NumericBaseValidator):
validate_branchNumber = KVKBranchNumberValidator()


class KVKRemoteBaseValidator:
class KVKRemoteValidatorMixin:
query_param: Literal["kvkNummer", "rsin", "vestigingsnummer"]
value_label: str

Expand All @@ -57,7 +57,7 @@ class KVKRemoteBaseValidator:
"too_short": _("%(type)s should have %(size)i characters."),
}

def __call__(self, value: str) -> bool:
def validate(self, value: str) -> bool:
assert self.query_param
query = cast(
SearchParams, {self.query_param: value}
Expand Down Expand Up @@ -85,7 +85,7 @@ def __call__(self, value: str) -> bool:

@register("kvk-kvkNumber")
@deconstructible
class KVKNumberRemoteValidator(BasePlugin[str], KVKRemoteBaseValidator):
class KVKNumberRemoteValidator(BasePlugin[str], KVKRemoteValidatorMixin):
query_param = "kvkNummer"
value_label = _("KvK number")

Expand All @@ -94,12 +94,12 @@ class KVKNumberRemoteValidator(BasePlugin[str], KVKRemoteBaseValidator):

def __call__(self, value: str, submission):
validate_kvk(value)
KVKRemoteBaseValidator.__call__(self, value)
super().validate(value)


@register("kvk-rsin")
@deconstructible
class KVKRSINRemoteValidator(BasePlugin[str], KVKRemoteBaseValidator):
class KVKRSINRemoteValidator(BasePlugin[str], KVKRemoteValidatorMixin):
query_param = "rsin"
value_label = _("RSIN")

Expand All @@ -108,12 +108,12 @@ class KVKRSINRemoteValidator(BasePlugin[str], KVKRemoteBaseValidator):

def __call__(self, value: str, submission):
validate_rsin(value)
KVKRemoteBaseValidator.__call__(self, value)
super().validate(value)


@register("kvk-branchNumber")
@deconstructible
class KVKBranchNumberRemoteValidator(BasePlugin[str], KVKRemoteBaseValidator):
class KVKBranchNumberRemoteValidator(BasePlugin[str], KVKRemoteValidatorMixin):
query_param = "vestigingsnummer"
value_label = _("Branch number")

Expand All @@ -122,4 +122,4 @@ class KVKBranchNumberRemoteValidator(BasePlugin[str], KVKRemoteBaseValidator):

def __call__(self, value: str, submission):
validate_branchNumber(value)
KVKRemoteBaseValidator.__call__(self, value)
super().validate(value)

0 comments on commit becb03f

Please sign in to comment.