BaseValidator
This class serves as a base for creating validation logic that compares a given value against a predefined limit. It provides a standard interface for cleaning input data, performing comparison checks, and raising validation errors with customizable messages. Subclasses can override the comparison and cleaning methods to implement specific validation rules.
Attributes
| Attribute | Type | Description |
|---|---|---|
| message | string = Ensure this value is %(limit_value)s (it is %(show_value)s). | The error message template used when validation fails, which can include placeholders for limit_value and show_value. |
| code | string = limit_value | The specific error code identifier associated with the ValidationError raised when the comparison fails. |
Constructor
Signature
def BaseValidator(
limit_value: any,
message: string = None
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| limit_value | any | The threshold or value to validate against. |
| message | string = None | An optional custom error message to override the default. |
Methods
compare()
@classmethod
def compare(
a: any,
b: any
) - > boolean
Performs the core comparison logic between the cleaned input value and the defined limit value.
Parameters
| Name | Type | Description |
|---|---|---|
| a | any | The cleaned input value being validated. |
| b | any | The limit value or threshold to compare against. |
Returns
| Type | Description |
|---|---|
boolean | A boolean indicating whether the validation condition is triggered (defaults to an identity check). |
clean()
@classmethod
def clean(
x: any
) - > any
Normalizes or pre-processes the input value before it is passed to the comparison method.
Parameters
| Name | Type | Description |
|---|---|---|
| x | any | The raw value that requires cleaning or type conversion. |
Returns
| Type | Description |
|---|---|
any | The processed version of the input value, ready for validation. |