| 1458 | """ |
| 1459 | |
| 1460 | def __init__(self, *args, **kwargs): |
| 1461 | choices = kwargs.pop("choices", None) |
| 1462 | super().__init__(*args, **kwargs) |
| 1463 | self.choices = [] |
| 1464 | # Keep the choices as a list of allowed Document class names |
| 1465 | if choices: |
| 1466 | for choice in choices: |
| 1467 | if isinstance(choice, str): |
| 1468 | self.choices.append(choice) |
| 1469 | elif isinstance(choice, type) and issubclass(choice, Document): |
| 1470 | self.choices.append(choice._class_name) |
| 1471 | else: |
| 1472 | # XXX ValidationError raised outside of the "validate" |
| 1473 | # method. |
| 1474 | self.error( |
| 1475 | "Invalid choices provided: must be a list of" |
| 1476 | "Document subclasses and/or str" |
| 1477 | ) |
| 1478 | |
| 1479 | def _validate_choices(self, value): |
| 1480 | if isinstance(value, dict): |