Validate that int() can be called on the input. Return the result of int() or None for empty values.
(self, value)
| 333 | ) |
| 334 | |
| 335 | def to_python(self, value): |
| 336 | """ |
| 337 | Validate that int() can be called on the input. Return the result |
| 338 | of int() or None for empty values. |
| 339 | """ |
| 340 | value = super().to_python(value) |
| 341 | if value in self.empty_values: |
| 342 | return None |
| 343 | if self.localize: |
| 344 | value = formats.sanitize_separators(value) |
| 345 | # Strip trailing decimal and zeros. |
| 346 | try: |
| 347 | value = int(self.re_decimal.sub("", str(value))) |
| 348 | except (ValueError, TypeError): |
| 349 | raise ValidationError(self.error_messages["invalid"], code="invalid") |
| 350 | return value |
| 351 | |
| 352 | def widget_attrs(self, widget): |
| 353 | attrs = super().widget_attrs(widget) |
nothing calls this directly
no test coverage detected