mirror of
https://github.com/django/django.git
synced 2025-07-07 11:19:12 +00:00
[soc2009/model-validation] Converted CommaSeparatedIntegerField to use validators
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@11394 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
8d4417c75d
commit
37ce9a5035
@ -40,6 +40,14 @@ def validate_ipv4_address(value):
|
|||||||
code="invalid"
|
code="invalid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
comma_separated_int_list_re = re.compile('^[\d,]+$')
|
||||||
|
|
||||||
|
def validate_comma_separated_integer_list(value):
|
||||||
|
if not comma_separated_int_list_re.search(smart_unicode(value)):
|
||||||
|
raise ValidationError(
|
||||||
|
_(u'Enter only digits separated by commas.'),
|
||||||
|
code="invalid"
|
||||||
|
)
|
||||||
|
|
||||||
class MaxValueValidator(object):
|
class MaxValueValidator(object):
|
||||||
def __init__(self, max_value):
|
def __init__(self, max_value):
|
||||||
|
@ -491,11 +491,9 @@ class CharField(Field):
|
|||||||
|
|
||||||
# TODO: Maybe move this into contrib, because it's specialized.
|
# TODO: Maybe move this into contrib, because it's specialized.
|
||||||
class CommaSeparatedIntegerField(CharField):
|
class CommaSeparatedIntegerField(CharField):
|
||||||
|
default_validators = [validators.validate_comma_separated_integer_list]
|
||||||
def formfield(self, **kwargs):
|
def formfield(self, **kwargs):
|
||||||
defaults = {
|
defaults = {
|
||||||
'form_class': forms.RegexField,
|
|
||||||
'regex': '^[\d,]+$',
|
|
||||||
'max_length': self.max_length,
|
|
||||||
'error_messages': {
|
'error_messages': {
|
||||||
'invalid': _(u'Enter only digits separated by commas.'),
|
'invalid': _(u'Enter only digits separated by commas.'),
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user