Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[soc2009/model-validation] Converted CommaSeparatedIntegerField to us…

…e validators

git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@11394 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 37ce9a503511eb612a5d17f9908cf4f6f72f9a7b 1 parent 8d4417c
@HonzaKral HonzaKral authored
View
8 django/core/validators.py
@@ -40,6 +40,14 @@ def validate_ipv4_address(value):
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):
def __init__(self, max_value):
View
4 django/db/models/fields/__init__.py
@@ -491,11 +491,9 @@ def formfield(self, **kwargs):
# TODO: Maybe move this into contrib, because it's specialized.
class CommaSeparatedIntegerField(CharField):
+ default_validators = [validators.validate_comma_separated_integer_list]
def formfield(self, **kwargs):
defaults = {
- 'form_class': forms.RegexField,
- 'regex': '^[\d,]+$',
- 'max_length': self.max_length,
'error_messages': {
'invalid': _(u'Enter only digits separated by commas.'),
}
Please sign in to comment.
Something went wrong with that request. Please try again.