Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #3281 -- newforms: URLField now works properly with required=Fa…

…lse and verify_exists=True together. Thanks, zendak

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4313 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f2a3deb0871c6cdbe04e1e0b36f4984c7c825bac 1 parent 6b31f95
Adrian Holovaty authored January 13, 2007
2  django/newforms/fields.py
@@ -288,6 +288,8 @@ def __init__(self, max_length=None, min_length=None, required=True, verify_exist
288 288
 
289 289
     def clean(self, value):
290 290
         value = RegexField.clean(self, value)
  291
+        if not self.required and value == u'':
  292
+            return value
291 293
         if self.verify_exists:
292 294
             import urllib2
293 295
             from django.conf import settings
5  tests/regressiontests/forms/tests.py
@@ -1331,6 +1331,11 @@
1331 1331
 Traceback (most recent call last):
1332 1332
 ...
1333 1333
 ValidationError: [u'This URL appears to be a broken link.']
  1334
+>>> f = URLField(verify_exists=True, required=False)
  1335
+>>> f.clean('')
  1336
+u''
  1337
+>>> f.clean('http://www.google.com') # This will fail if there's no Internet connection
  1338
+u'http://www.google.com'
1334 1339
 
1335 1340
 EmailField also access min_length and max_length parameters, for convenience.
1336 1341
 >>> f = URLField(min_length=15, max_length=20)

0 notes on commit f2a3deb

Please sign in to comment.
Something went wrong with that request. Please try again.