(self, *, format=empty, **kwargs)
| 1374 | } |
| 1375 | |
| 1376 | def __init__(self, *, format=empty, **kwargs): |
| 1377 | self.max_value = kwargs.pop('max_value', None) |
| 1378 | self.min_value = kwargs.pop('min_value', None) |
| 1379 | if format is not empty: |
| 1380 | if format is None or (isinstance(format, str) and format.lower() in (ISO_8601, DJANGO_DURATION_FORMAT)): |
| 1381 | self.format = format |
| 1382 | elif isinstance(format, str): |
| 1383 | raise ValueError( |
| 1384 | f"Unknown duration format provided, got '{format}'" |
| 1385 | " while expecting 'django', 'iso-8601' or `None`." |
| 1386 | ) |
| 1387 | else: |
| 1388 | raise TypeError( |
| 1389 | "duration format must be either str or `None`," |
| 1390 | f" not {type(format).__name__}" |
| 1391 | ) |
| 1392 | super().__init__(**kwargs) |
| 1393 | if self.max_value is not None: |
| 1394 | message = lazy_format(self.error_messages['max_value'], max_value=self.max_value) |
| 1395 | self.validators.append( |
| 1396 | MaxValueValidator(self.max_value, message=message)) |
| 1397 | if self.min_value is not None: |
| 1398 | message = lazy_format(self.error_messages['min_value'], min_value=self.min_value) |
| 1399 | self.validators.append( |
| 1400 | MinValueValidator(self.min_value, message=message)) |
| 1401 | |
| 1402 | def to_internal_value(self, value): |
| 1403 | if isinstance(value, datetime.timedelta): |
nothing calls this directly
no test coverage detected