Ticket #5903: decimal_field_default_5903.patch

File decimal_field_default_5903.patch, 1.4 KB (added by Maciej Wiśniowski, 17 years ago)

Patch that adds decimal.Decimal to smart_unicode

  • django/utils/encoding.py

     
    44
    55from django.utils.functional import Promise
    66from django.utils.safestring import SafeData, mark_safe
     7try:
     8    import decimal
     9except ImportError:
     10    from django.utils import _decimal as decimal    # for Python 2.3
    711
    812class DjangoUnicodeDecodeError(UnicodeDecodeError):
    913    def __init__(self, obj, *args):
     
    4347
    4448    If strings_only is True, don't convert (some) non-string-like objects.
    4549    """
    46     if strings_only and isinstance(s, (types.NoneType, int, long, datetime.datetime, datetime.date, datetime.time, float)):
     50    if strings_only and isinstance(s, (types.NoneType, int, long, datetime.datetime, datetime.date, datetime.time, float, decimal.Decimal)):
    4751        return s
    4852    try:
    4953        if not isinstance(s, basestring,):
  • tests/regressiontests/model_fields/tests.py

     
    1515Traceback (most recent call last):
    1616...
    1717ValidationError: [u'This value must be a decimal number.']
     18
     19# test default value
     20>>> import decimal
     21>>> f = DecimalField(default=decimal.Decimal("0.00"))
     22>>> f.get_default()
     23Decimal("0.00")
    1824"""
Back to Top