Author: Honza_Kral
Date: 2009-06-02 21:37:20 -0500 (Tue, 02 Jun 2009)
New Revision: 10903
Modified:
django/branches/soc2009/model-validation/django/forms/fields.py
Log:
[soc2009/model-validation] DecimalField done
Modified: django/branches/soc2009/model-validation/django/forms/fields.py
===================================================================
--- django/branches/soc2009/model-validation/django/forms/fields.py
2009-06-03 02:37:04 UTC (rev 10902)
+++ django/branches/soc2009/model-validation/django/forms/fields.py
2009-06-03 02:37:20 UTC (rev 10903)
@@ -208,6 +208,8 @@
def validate(self, value):
super(IntegerField, self).validate(value)
+ if value in EMPTY_VALUES:
+ return
if self.max_value is not None and value > self.max_value:
raise ValidationError(self.error_messages['max_value'] %
self.max_value)
if self.min_value is not None and value < self.min_value:
@@ -250,22 +252,26 @@
self.max_digits, self.decimal_places = max_digits, decimal_places
Field.__init__(self, *args, **kwargs)
- def clean(self, value):
+ def to_python(self, value):
"""
Validates that the input is a decimal number. Returns a Decimal
instance. Returns None for empty values. Ensures that there are no more
than max_digits in the number, and no more than decimal_places digits
after the decimal point.
"""
- super(DecimalField, self).clean(value)
- if not self.required and value in EMPTY_VALUES:
+ if value in EMPTY_VALUES:
return None
value = smart_str(value).strip()
try:
value = Decimal(value)
except DecimalException:
raise ValidationError(self.error_messages['invalid'])
+ return value
+ def validate(self, value):
+ super(DecimalField, self).validate(value)
+ if value in EMPTY_VALUES:
+ return
sign, digittuple, exponent = value.as_tuple()
decimals = abs(exponent)
# digittuple doesn't include any leading zeros.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---