diff --git a/django/core/validators.py b/django/core/validators.py
index 69e60eb..d17620c 100644
a
|
b
|
class URLValidator(RegexValidator):
|
51 | 51 | r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip |
52 | 52 | r'(?::\d+)?' # optional port |
53 | 53 | r'(?:/?|[/?]\S+)$', re.IGNORECASE) |
| 54 | message = _(u'Enter a valid URL.') |
54 | 55 | |
55 | 56 | def __init__(self, verify_exists=False, |
56 | 57 | validator_user_agent=URL_VALIDATOR_USER_AGENT): |
… |
… |
class URLValidator(RegexValidator):
|
128 | 129 | else: |
129 | 130 | opener.open(req) |
130 | 131 | except ValueError: |
131 | | raise ValidationError(_(u'Enter a valid URL.'), code='invalid') |
| 132 | raise ValidationError(self.message, code='invalid') |
132 | 133 | except: # urllib2.URLError, httplib.InvalidURL, etc. |
133 | 134 | raise broken_error |
134 | 135 | |
diff --git a/django/forms/fields.py b/django/forms/fields.py
index 8e727b4..ca6b68b 100644
a
|
b
|
class Field(object):
|
46 | 46 | widget = TextInput # Default widget to use when rendering this type of Field. |
47 | 47 | hidden_widget = HiddenInput # Default widget to use when rendering this as "hidden". |
48 | 48 | default_validators = [] # Default set of validators |
| 49 | # Add an 'invalid' entry to this dictionary if you want a specific field error |
| 50 | # message not raised by the field validators. |
49 | 51 | default_error_messages = { |
50 | 52 | 'required': _(u'This field is required.'), |
51 | | 'invalid': _(u'Enter a valid value.'), |
52 | 53 | } |
53 | 54 | |
54 | 55 | # Tracks each time a Field instance is created. Used to retain order. |
diff --git a/tests/modeltests/validation/tests.py b/tests/modeltests/validation/tests.py
index a7e13e7..c391ca9 100644
a
|
b
|
class BaseModelValidationTests(ValidationTestCase):
|
64 | 64 | |
65 | 65 | def test_wrong_url_value_raises_error(self): |
66 | 66 | mtv = ModelToValidate(number=10, name='Some Name', url='not a url') |
67 | | self.assertFieldFailsValidationWithMessage(mtv.full_clean, 'url', [u'Enter a valid value.']) |
| 67 | self.assertFieldFailsValidationWithMessage(mtv.full_clean, 'url', [u'Enter a valid URL.']) |
68 | 68 | |
69 | 69 | #The tests below which use url_verify are deprecated |
70 | 70 | def test_correct_url_but_nonexisting_gives_404(self): |
diff --git a/tests/regressiontests/forms/tests/validators.py b/tests/regressiontests/forms/tests/validators.py
index cadf660..5d80ad4 100644
a
|
b
|
from django.core import validators
|
3 | 3 | from django.core.exceptions import ValidationError |
4 | 4 | from django.utils.unittest import TestCase |
5 | 5 | |
| 6 | class UserForm(forms.Form): |
| 7 | full_name = forms.CharField( |
| 8 | max_length = 50, |
| 9 | validators = [ |
| 10 | validators.validate_integer, |
| 11 | validators.validate_email, |
| 12 | ] |
| 13 | ) |
| 14 | string = forms.CharField( |
| 15 | max_length = 50, |
| 16 | validators = [ |
| 17 | validators.RegexValidator( |
| 18 | regex='^[a-zA-Z]*$', |
| 19 | message=u"Letters only.", |
| 20 | ) |
| 21 | ] |
| 22 | ) |
6 | 23 | |
7 | 24 | class TestFieldWithValidators(TestCase): |
8 | 25 | def test_all_errors_get_reported(self): |
9 | | field = forms.CharField( |
10 | | validators=[validators.validate_integer, validators.validate_email] |
11 | | ) |
12 | | self.assertRaises(ValidationError, field.clean, 'not int nor mail') |
| 26 | form = UserForm({'full_name': u'not int nor mail', 'string': u'2 is not correct'}) |
| 27 | self.assertRaises(ValidationError, form.fields['full_name'].clean, 'not int nor mail') |
13 | 28 | try: |
14 | | field.clean('not int nor mail') |
| 29 | form.fields['full_name'].clean('not int nor mail') |
15 | 30 | except ValidationError, e: |
16 | 31 | self.assertEqual(2, len(e.messages)) |
| 32 | |
| 33 | self.assertFalse(form.is_valid()) |
| 34 | self.assertEqual(form.errors['string'], [u"Letters only."]) |