Ticket #11716: 11716.diff
File 11716.diff, 12.9 KB (added by , 14 years ago) |
---|
-
django/contrib/admin/widgets.py
diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index 0f567bd..9f99c5d 100644
a b from django.utils.translation import ugettext as _ 13 13 from django.utils.safestring import mark_safe 14 14 from django.utils.encoding import force_unicode 15 15 from django.conf import settings 16 from django.core.exceptions import ValidationError 16 17 from django.core.urlresolvers import reverse, NoReverseMatch 17 18 18 19 class FilteredSelectMultiple(forms.SelectMultiple): … … class ForeignKeyRawIdWidget(forms.TextInput): 147 148 try: 148 149 obj = self.rel.to._default_manager.using(self.db).get(**{key: value}) 149 150 return ' <strong>%s</strong>' % escape(truncate_words(obj, 14)) 150 except (Val ueError, self.rel.to.DoesNotExist):151 except (ValidationError, ValueError, self.rel.to.DoesNotExist): 151 152 return '' 152 153 153 154 class ManyToManyRawIdWidget(ForeignKeyRawIdWidget): -
django/contrib/comments/views/utils.py
diff --git a/django/contrib/comments/views/utils.py b/django/contrib/comments/views/utils.py index 8b729d2..458da03 100644
a b from django.http import HttpResponseRedirect 8 8 from django.core import urlresolvers 9 9 from django.shortcuts import render_to_response 10 10 from django.template import RequestContext 11 from django.core.exceptions import ObjectDoesNotExist 11 from django.core.exceptions import ObjectDoesNotExist, ValidationError 12 12 from django.contrib import comments 13 13 14 14 def next_redirect(data, default, default_view, **get_kwargs): … … def confirmation_view(template, doc="Display a confirmation view."): 39 39 if 'c' in request.GET: 40 40 try: 41 41 comment = comments.get_model().objects.get(pk=request.GET['c']) 42 except (ObjectDoesNotExist, Val ueError):42 except (ObjectDoesNotExist, ValidationError): 43 43 pass 44 44 return render_to_response(template, 45 45 {'comment': comment}, -
django/contrib/contenttypes/views.py
diff --git a/django/contrib/contenttypes/views.py b/django/contrib/contenttypes/views.py index ac0feff..5163f21 100644
a b 1 1 from django import http 2 2 from django.contrib.contenttypes.models import ContentType 3 3 from django.contrib.sites.models import Site, get_current_site 4 from django.core.exceptions import ObjectDoesNotExist 4 from django.core.exceptions import ObjectDoesNotExist, ValidationError 5 5 6 6 def shortcut(request, content_type_id, object_id): 7 7 "Redirect to an object's page based on a content-type ID and an object ID." … … def shortcut(request, content_type_id, object_id): 11 11 if not content_type.model_class(): 12 12 raise http.Http404("Content type %s object has no associated model" % content_type_id) 13 13 obj = content_type.get_object_for_this_type(pk=object_id) 14 except (ObjectDoesNotExist, Val ueError):14 except (ObjectDoesNotExist, ValidationError): 15 15 raise http.Http404("Content type %s object %s doesn't exist" % (content_type_id, object_id)) 16 16 try: 17 17 absurl = obj.get_absolute_url() -
django/db/models/fields/__init__.py
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index fd0a295..3831bb2 100644
a b class AutoField(Field): 474 474 pass 475 475 476 476 def get_prep_value(self, value): 477 if value is None: 478 return None 479 return int(value) 477 return self.to_python(value) 480 478 481 479 def contribute_to_class(self, cls, name): 482 480 assert not cls._meta.has_auto_field, "A model can't have more than one AutoField." … … class BooleanField(Field): 523 521 return super(BooleanField, self).get_prep_lookup(lookup_type, value) 524 522 525 523 def get_prep_value(self, value): 526 if value is None: 527 return None 528 return bool(value) 524 return self.to_python(value) 529 525 530 526 def formfield(self, **kwargs): 531 527 # Unlike most fields, BooleanField figures out include_blank from … … class FloatField(Field): 843 839 description = _("Floating point number") 844 840 845 841 def get_prep_value(self, value): 846 if value is None: 847 return None 848 return float(value) 842 return self.to_python(value) 849 843 850 844 def get_internal_type(self): 851 845 return "FloatField" … … class IntegerField(Field): 871 865 description = _("Integer") 872 866 873 867 def get_prep_value(self, value): 874 if value is None: 875 return None 876 return int(value) 868 return self.to_python(value) 877 869 878 870 def get_prep_lookup(self, lookup_type, value): 879 871 if (lookup_type == 'gte' or lookup_type == 'lt') \ … … class NullBooleanField(Field): 963 955 return super(NullBooleanField, self).get_prep_lookup(lookup_type, value) 964 956 965 957 def get_prep_value(self, value): 966 if value is None: 967 return None 968 return bool(value) 958 return self.to_python(value) 969 959 970 960 def formfield(self, **kwargs): 971 961 defaults = { … … class XMLField(TextField): 1138 1128 def __init__(self, verbose_name=None, name=None, schema_path=None, **kwargs): 1139 1129 self.schema_path = schema_path 1140 1130 Field.__init__(self, verbose_name, name, **kwargs) 1141 -
django/forms/models.py
diff --git a/django/forms/models.py b/django/forms/models.py index 2f41dbf..15faa5b 100644
a b class ModelMultipleChoiceField(ModelChoiceField): 1040 1040 for pk in value: 1041 1041 try: 1042 1042 self.queryset.filter(pk=pk) 1043 except Val ueError:1043 except ValidationError: 1044 1044 raise ValidationError(self.error_messages['invalid_pk_value'] % pk) 1045 1045 qs = self.queryset.filter(pk__in=value) 1046 1046 pks = set([force_unicode(o.pk) for o in qs]) -
tests/modeltests/expressions/tests.py
diff --git a/tests/modeltests/expressions/tests.py b/tests/modeltests/expressions/tests.py index 0a136ae..7305ffa 100644
a b 1 from django.core.exceptions import FieldError 1 from django.core.exceptions import FieldError, ValidationError 2 2 from django.db.models import F 3 3 from django.test import TestCase 4 4 … … class ExpressionsTests(TestCase): 215 215 ceo=test_gmbh.ceo 216 216 ) 217 217 acme.num_employees = F("num_employees") + 16 218 self.assertRaises( TypeError, acme.save)218 self.assertRaises(ValidationError, acme.save) -
tests/regressiontests/admin_widgets/tests.py
diff --git a/tests/regressiontests/admin_widgets/tests.py b/tests/regressiontests/admin_widgets/tests.py index 4f9abb6..14945a0 100644
a b class AdminForeignKeyRawIdWidget(DjangoTestCase): 170 170 'Select a valid choice. That choice is not one of the available choices.') 171 171 172 172 def test_invalid_target_id(self): 173 response = self.client.post('%s/admin_widgets/event/add/' % self.admin_root, 174 {"band": -1234}) 175 self.assertContains(response, 176 'Select a valid choice. That choice is not one of the available choices.') 173 177 174 for test_str in ('Iñtërnâtiônàlizætiøn', "1234'" , -1234):178 for test_str in ('Iñtërnâtiônàlizætiøn', "1234'"): 175 179 # This should result in an error message, not a server exception. 176 180 response = self.client.post('%s/admin_widgets/event/add/' % self.admin_root, 177 181 {"band": test_str}) 178 182 179 self.assertContains(response, 180 'Select a valid choice. That choice is not one of the available choices.') 183 self.assertContains(response, 'This value must be an integer.') 181 184 182 185 183 186 class FilteredSelectMultipleWidgetTest(TestCase): -
tests/regressiontests/model_fields/tests.py
diff --git a/tests/regressiontests/model_fields/tests.py b/tests/regressiontests/model_fields/tests.py index a0b4593..5d1c3f1 100644
a b class BasicFieldTests(test.TestCase): 48 48 except ValidationError, e: 49 49 self.fail("NullBooleanField failed validation with value of None: %s" % e.messages) 50 50 51 class AutoFieldTests(test.TestCase): 52 def test_to_python(self): 53 f = models.AutoField(primary_key=True) 54 self.assertEqual(f.to_python(3), 3) 55 self.assertEqual(f.to_python("3"), 3) 56 self.assertEqual(f.to_python(None), None) 57 self.assertRaises(ValidationError, f.to_python, "abc") 58 59 def test_get_db_prep_value(self): 60 from django.db import connection 61 f = models.AutoField(primary_key=True) 62 self.assertEqual(f.get_db_prep_value(3, connection=connection), 3) 63 self.assertEqual(f.get_db_prep_value("3", connection=connection), 3) 64 self.assertEqual(f.get_db_prep_value(None, connection=connection), None) 65 self.assertRaises(ValidationError, f.get_db_prep_value, "abc", connection=connection) 66 51 67 class DecimalFieldTests(test.TestCase): 52 68 def test_to_python(self): 53 69 f = models.DecimalField(max_digits=4, decimal_places=2) 54 70 self.assertEqual(f.to_python(3), Decimal("3")) 55 71 self.assertEqual(f.to_python("3.14"), Decimal("3.14")) 72 self.assertEqual(f.to_python(None), None) 56 73 self.assertRaises(ValidationError, f.to_python, "abc") 57 74 75 def test_get_db_prep_value(self): 76 from django.db import connection 77 f = models.DecimalField(max_digits=4, decimal_places=2) 78 self.assertEqual(f.get_db_prep_value(3, connection=connection), 3) 79 self.assertEqual(f.get_db_prep_value("3.14", connection=connection), Decimal("3.14")) 80 self.assertEqual(f.to_python(None), None) 81 self.assertRaises(ValidationError, f.get_db_prep_value, "abc", connection=connection) 82 58 83 def test_default(self): 59 84 f = models.DecimalField(default=Decimal("0.00")) 60 85 self.assertEqual(f.get_default(), Decimal("0.00")) … … class BooleanFieldTests(unittest.TestCase): 128 153 self.assertEqual(f.get_db_prep_lookup('exact', False, connection=connection), [False]) 129 154 self.assertEqual(f.get_db_prep_lookup('exact', '0', connection=connection), [False]) 130 155 self.assertEqual(f.get_db_prep_lookup('exact', 0, connection=connection), [False]) 131 self.assertEqual(f.get_db_prep_lookup('exact', None, connection=connection), [None]) 156 132 157 133 158 def _test_to_python(self, f): 134 159 self.assertTrue(f.to_python(1) is True) 135 160 self.assertTrue(f.to_python(0) is False) 136 161 137 162 def test_booleanfield_get_db_prep_lookup(self): 163 from django.db import connection 138 164 self._test_get_db_prep_lookup(models.BooleanField()) 165 self.assertRaises(ValidationError, models.BooleanField().get_db_prep_lookup, 'exact', None, connection=connection) 139 166 140 167 def test_nullbooleanfield_get_db_prep_lookup(self): 168 from django.db import connection 141 169 self._test_get_db_prep_lookup(models.NullBooleanField()) 170 self.assertEqual(models.NullBooleanField().get_db_prep_lookup('exact', None, connection=connection), [None]) 142 171 143 172 def test_booleanfield_to_python(self): 144 173 self._test_to_python(models.BooleanField()) … … class ValidationTest(test.TestCase): 270 299 f = models.BooleanField() 271 300 self.assertRaises(ValidationError, f.clean, None, None) 272 301 302 class IntegerFieldTests(test.TestCase): 303 def test_to_python(self): 304 f = models.IntegerField() 305 self.assertEqual(f.to_python(3), 3) 306 self.assertEqual(f.to_python("3"), 3) 307 self.assertEqual(f.to_python(None), None) 308 self.assertRaises(ValidationError, f.to_python, "abc") 309 310 def test_get_db_prep_value(self): 311 from django.db import connection 312 f = models.IntegerField() 313 self.assertEqual(f.get_db_prep_value(3, connection=connection), 3) 314 self.assertEqual(f.get_db_prep_value("3", connection=connection), 3) 315 self.assertEqual(f.get_db_prep_value(None, connection=connection), None) 316 self.assertRaises(ValidationError, f.get_db_prep_value, "abc", connection=connection) 317 318 class FloatFieldTests(test.TestCase): 319 def test_to_python(self): 320 f = models.FloatField() 321 self.assertEqual(f.to_python(3), float("3")) 322 self.assertEqual(f.to_python("3.14"), float("3.14")) 323 self.assertEqual(f.to_python(None), None) 324 self.assertRaises(ValidationError, f.to_python, "abc") 325 326 def test_get_db_prep_value(self): 327 from django.db import connection 328 f = models.FloatField() 329 self.assertEqual(f.get_db_prep_value(3, connection=connection), float(3)) 330 self.assertEqual(f.get_db_prep_value("3.14", connection=connection), float("3.14")) 331 self.assertEqual(f.to_python(None), None) 332 self.assertRaises(ValidationError, f.get_db_prep_value, "abc", connection=connection) 273 333 274 334 class BigIntegerFieldTests(test.TestCase): 275 335 def test_limits(self):