Ticket #4287: inf-bug.2.patch
File inf-bug.2.patch, 3.3 KB (added by , 13 years ago) |
---|
-
django/db/models/fields/__init__.py
6 6 import math 7 7 from itertools import tee 8 8 9 from django.db import connection 9 from django.db import connection, utils 10 10 from django.db.models.query_utils import QueryWrapper 11 11 from django.conf import settings 12 12 from django import forms … … 848 848 empty_strings_allowed = False 849 849 default_error_messages = { 850 850 'invalid': _("This value must be a float."), 851 'no-infinity': _("This field has no infinity enabled"), 851 852 } 852 853 description = _("Floating point number") 853 854 855 def __init__(self, allow_infinity=False, *args, **kwargs): 856 if allow_infinity and not(connection.features.supports_infinity_floats): 857 raise utils.DatabaseError("Your database does not support storing infinity values.") 858 self.allow_infinity = allow_infinity 859 super(FloatField, self).__init__(*args, **kwargs) 860 854 861 def get_prep_value(self, value): 855 862 if value is None: 856 863 return None … … 863 870 if value is None: 864 871 return value 865 872 try: 866 returnfloat(value)873 float_value = float(value) 867 874 except (TypeError, ValueError): 868 875 raise exceptions.ValidationError(self.error_messages['invalid']) 876 if not(self.allow_infinity) and float_value in (float('inf'), float('-inf')): 877 raise exceptions.ValidationError(self.error_messages['no-infinity']) 878 else: 879 return float_value 869 880 870 881 def formfield(self, **kwargs): 871 882 defaults = {'form_class': forms.FloatField} -
django/db/backends/sqlite3/base.py
57 57 supports_unspecified_pk = True 58 58 supports_1000_query_parameters = False 59 59 supports_mixed_date_datetime_comparisons = False 60 supports_infinity_floats = True 60 61 61 62 def _supports_stddev(self): 62 63 """Confirm support for STDDEV and related stats functions -
django/db/backends/__init__.py
335 335 # date_interval_sql can properly handle mixed Date/DateTime fields and timedeltas 336 336 supports_mixed_date_datetime_comparisons = True 337 337 338 # Can an float store infinity? 339 supports_infinity_floats = False 340 338 341 # Features that need to be confirmed at runtime 339 342 # Cache whether the confirmation has been performed. 340 343 _confirmed = False -
django/forms/fields.py
235 235 'invalid': _(u'Enter a number.'), 236 236 } 237 237 238 def __init__(self, store_infinity=False, *args, **kwargs): 239 self.store_infinity = store_infinity 240 super(IntegerField, self).__init__(*args, **kwargs) 241 238 242 def to_python(self, value): 239 243 """ 240 244 Validates that float() can be called on the input. Returns the result