1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #21638: Validators are now comparable, stops infinite user mig'ns

This commit is contained in:
Andrew Godwin
2014-01-19 18:56:16 +00:00
parent 3f1a008266
commit a68f325791
2 changed files with 65 additions and 0 deletions

View File

@@ -40,6 +40,9 @@ class RegexValidator(object):
if not self.regex.search(force_text(value)):
raise ValidationError(self.message, code=self.code)
def __eq__(self, other):
return isinstance(other, RegexValidator) and (self.regex == other.regex) and (self.message == other.message) and (self.code == other.code)
@deconstructible
class URLValidator(RegexValidator):
@@ -139,6 +142,9 @@ class EmailValidator(object):
pass
raise ValidationError(self.message, code=self.code)
def __eq__(self, other):
return isinstance(other, EmailValidator) and (self.domain_whitelist == other.domain_whitelist) and (self.message == other.message) and (self.code == other.code)
validate_email = EmailValidator()
slug_re = re.compile(r'^[-a-zA-Z0-9_]+$')
@@ -205,6 +211,9 @@ class BaseValidator(object):
if self.compare(cleaned, self.limit_value):
raise ValidationError(self.message, code=self.code, params=params)
def __eq__(self, other):
return isinstance(other, self.__class__) and (self.limit_value == other.limit_value) and (self.message == other.message) and (self.code == other.code)
@deconstructible
class MaxValueValidator(BaseValidator):