Ticket #12539: patch_and_test.diff

File patch_and_test.diff, 3.0 KB (added by Bernd Schlapsi <brot@…>, 15 years ago)

Patch for this issue and a testcase wich fails without the patch

  • django/db/models/fields/__init__.py

     
    480480        Field.__init__(self, *args, **kwargs)
    481481
    482482    def to_python(self, value):
    483         if value is None:
    484             return value
     483        if value in validators.EMPTY_VALUES:
     484            return None
    485485        try:
    486486            return int(value)
    487487        except (TypeError, ValueError):
     
    609609        return "DateField"
    610610
    611611    def to_python(self, value):
    612         if value is None:
    613             return value
     612        if value in validators.EMPTY_VALUES:
     613            return None
    614614        if isinstance(value, datetime.datetime):
    615615            return value.date()
    616616        if isinstance(value, datetime.date):
     
    684684        return "DateTimeField"
    685685
    686686    def to_python(self, value):
    687         if value is None:
    688             return value
     687        if value in validators.EMPTY_VALUES:
     688            return None
    689689        if isinstance(value, datetime.datetime):
    690690            return value
    691691        if isinstance(value, datetime.date):
     
    756756        return "DecimalField"
    757757
    758758    def to_python(self, value):
    759         if value is None:
    760             return value
     759        if value in validators.EMPTY_VALUES:
     760            return None
    761761        try:
    762762            return decimal.Decimal(value)
    763763        except decimal.InvalidOperation:
     
    844844        return "FloatField"
    845845
    846846    def to_python(self, value):
    847         if value is None:
    848             return value
     847        if value in validators.EMPTY_VALUES:
     848            return None
    849849        try:
    850850            return float(value)
    851851        except (TypeError, ValueError):
     
    872872        return "IntegerField"
    873873
    874874    def to_python(self, value):
    875         if value is None:
    876             return value
     875        if value in validators.EMPTY_VALUES:
     876            return None
    877877        try:
    878878            return int(value)
    879879        except (TypeError, ValueError):
     
    10281028        return "TimeField"
    10291029
    10301030    def to_python(self, value):
    1031         if value is None:
     1031        if value in validators.EMPTY_VALUES:
    10321032            return None
    10331033        if isinstance(value, datetime.time):
    10341034            return value
  • tests/regressiontests/forms/models.py

     
    7373>>> f.is_valid()
    7474False
    7575
     76# BoundaryForm with localflavor form field
     77>>> from django.contrib.localflavor.at.forms import ATZipCodeField
     78>>> class BoundaryForm(ModelForm):
     79...     positive_integer = ATZipCodeField(required=False)
     80...     class Meta:
     81...         model = BoundaryModel
     82>>> f = BoundaryForm({})
     83>>> f.full_clean()
     84>>> f.errors
     85{}
     86
    7687# Formfield initial values ########
    7788If the model has default values for some fields, they are used as the formfield
    7889initial values.
Back to Top