304 | | decimals = abs(exponent) |
305 | | # digittuple doesn't include any leading zeros. |
306 | | digits = len(digittuple) |
307 | | if decimals > digits: |
308 | | # We have leading zeros up to or past the decimal point. Count |
309 | | # everything past the decimal point as a digit. We do not count |
310 | | # 0 before the decimal point as a digit since that would mean |
311 | | # we would not allow max_digits = decimal_places. |
312 | | digits = decimals |
313 | | whole_digits = digits - decimals |
314 | | |
315 | | if self.max_digits is not None and digits > self.max_digits: |
316 | | raise ValidationError(self.error_messages['max_digits'] % self.max_digits) |
317 | | if self.decimal_places is not None and decimals > self.decimal_places: |
318 | | raise ValidationError(self.error_messages['max_decimal_places'] % self.decimal_places) |
319 | | if self.max_digits is not None and self.decimal_places is not None and whole_digits > (self.max_digits - self.decimal_places): |
320 | | raise ValidationError(self.error_messages['max_whole_digits'] % (self.max_digits - self.decimal_places)) |
| 304 | if exponent < 0: |
| 305 | decimals = abs(exponent) |
| 306 | # digittuple doesn't include any leading zeros. |
| 307 | digits = len(digittuple) |
| 308 | if decimals > digits: |
| 309 | # We have leading zeros up to or past the decimal point. Count |
| 310 | # everything past the decimal point as a digit. We do not count |
| 311 | # 0 before the decimal point as a digit since that would mean |
| 312 | # we would not allow max_digits = decimal_places. |
| 313 | digits = decimals |
| 314 | whole_digits = digits - decimals |
| 315 | |
| 316 | if self.max_digits is not None and digits > self.max_digits: |
| 317 | raise ValidationError(self.error_messages['max_digits'] % self.max_digits) |
| 318 | if self.decimal_places is not None and decimals > self.decimal_places: |
| 319 | raise ValidationError(self.error_messages['max_decimal_places'] % self.decimal_places) |
| 320 | if self.max_digits is not None and self.decimal_places is not None and whole_digits > (self.max_digits - self.decimal_places): |
| 321 | raise ValidationError(self.error_messages['max_whole_digits'] % (self.max_digits - self.decimal_places)) |
| 322 | else: |
| 323 | digits = len(digittuple) + exponent |
| 324 | if self.max_digits is not None and digits > self.max_digits: |
| 325 | raise ValidationError(self.error_messages['max_digits'] % self.max_digits) |
| 326 | |
| 327 | |