Loading django/db/backends/__init__.py +0 −2 Original line number Diff line number Diff line Loading @@ -1195,8 +1195,6 @@ class BaseDatabaseOperations(object): Transform a decimal.Decimal value to an object compatible with what is expected by the backend driver for decimal (numeric) columns. """ if value is None: return None return utils.format_number(value, max_digits, decimal_places) def year_lookup_bounds_for_date_field(self, value): Loading django/db/backends/oracle/base.py +1 −3 Original line number Diff line number Diff line Loading @@ -312,9 +312,7 @@ WHEN (new.%(col_name)s IS NULL) return value def convert_decimalfield_value(self, value, field): if value is not None: value = backend_utils.typecast_decimal(field.format_number(value)) return value return backend_utils.typecast_decimal(field.format_number(value)) # cx_Oracle always returns datetime.datetime objects for # DATE and TIMESTAMP columns, but Django wants to see a Loading django/db/backends/sqlite3/base.py +1 −3 Original line number Diff line number Diff line Loading @@ -277,9 +277,7 @@ class DatabaseOperations(BaseDatabaseOperations): return converters def convert_decimalfield_value(self, value, field): if value is not None: value = backend_utils.typecast_decimal(field.format_number(value)) return value return backend_utils.typecast_decimal(field.format_number(value)) def convert_datefield_value(self, value, field): if value is not None and not isinstance(value, datetime.date): Loading django/db/backends/utils.py +12 −3 Original line number Diff line number Diff line Loading @@ -191,9 +191,18 @@ def format_number(value, max_digits, decimal_places): Formats a number into a string with the requisite number of digits and decimal places. """ if value is None: return None if isinstance(value, decimal.Decimal): context = decimal.getcontext().copy() if max_digits is not None: context.prec = max_digits return "{0:f}".format(value.quantize(decimal.Decimal(".1") ** decimal_places, context=context)) if decimal_places is not None: value = value.quantize(decimal.Decimal(".1") ** decimal_places, context=context) else: context.traps[decimal.Rounded] = 1 value = context.create_decimal(value) return "{:f}".format(value) if decimal_places is not None: return "%.*f" % (decimal_places, value) return "{:f}".format(value) django/db/models/expressions.py +1 −1 Original line number Diff line number Diff line Loading @@ -255,7 +255,7 @@ class ExpressionNode(CombinableMixin): elif internal_type.endswith('IntegerField'): return int(value) elif internal_type == 'DecimalField': return backend_utils.typecast_decimal(field.format_number(value)) return backend_utils.typecast_decimal(value) return value def get_lookup(self, lookup): Loading Loading
django/db/backends/__init__.py +0 −2 Original line number Diff line number Diff line Loading @@ -1195,8 +1195,6 @@ class BaseDatabaseOperations(object): Transform a decimal.Decimal value to an object compatible with what is expected by the backend driver for decimal (numeric) columns. """ if value is None: return None return utils.format_number(value, max_digits, decimal_places) def year_lookup_bounds_for_date_field(self, value): Loading
django/db/backends/oracle/base.py +1 −3 Original line number Diff line number Diff line Loading @@ -312,9 +312,7 @@ WHEN (new.%(col_name)s IS NULL) return value def convert_decimalfield_value(self, value, field): if value is not None: value = backend_utils.typecast_decimal(field.format_number(value)) return value return backend_utils.typecast_decimal(field.format_number(value)) # cx_Oracle always returns datetime.datetime objects for # DATE and TIMESTAMP columns, but Django wants to see a Loading
django/db/backends/sqlite3/base.py +1 −3 Original line number Diff line number Diff line Loading @@ -277,9 +277,7 @@ class DatabaseOperations(BaseDatabaseOperations): return converters def convert_decimalfield_value(self, value, field): if value is not None: value = backend_utils.typecast_decimal(field.format_number(value)) return value return backend_utils.typecast_decimal(field.format_number(value)) def convert_datefield_value(self, value, field): if value is not None and not isinstance(value, datetime.date): Loading
django/db/backends/utils.py +12 −3 Original line number Diff line number Diff line Loading @@ -191,9 +191,18 @@ def format_number(value, max_digits, decimal_places): Formats a number into a string with the requisite number of digits and decimal places. """ if value is None: return None if isinstance(value, decimal.Decimal): context = decimal.getcontext().copy() if max_digits is not None: context.prec = max_digits return "{0:f}".format(value.quantize(decimal.Decimal(".1") ** decimal_places, context=context)) if decimal_places is not None: value = value.quantize(decimal.Decimal(".1") ** decimal_places, context=context) else: context.traps[decimal.Rounded] = 1 value = context.create_decimal(value) return "{:f}".format(value) if decimal_places is not None: return "%.*f" % (decimal_places, value) return "{:f}".format(value)
django/db/models/expressions.py +1 −1 Original line number Diff line number Diff line Loading @@ -255,7 +255,7 @@ class ExpressionNode(CombinableMixin): elif internal_type.endswith('IntegerField'): return int(value) elif internal_type == 'DecimalField': return backend_utils.typecast_decimal(field.format_number(value)) return backend_utils.typecast_decimal(value) return value def get_lookup(self, lookup): Loading