(self, value)
| 245 | pass |
| 246 | |
| 247 | def _validate_choices(self, value): |
| 248 | Document = _import_class("Document") |
| 249 | EmbeddedDocument = _import_class("EmbeddedDocument") |
| 250 | |
| 251 | choice_list = self.choices |
| 252 | if isinstance(next(iter(choice_list)), (list, tuple)): |
| 253 | # next(iter) is useful for sets |
| 254 | choice_list = [k for k, _ in choice_list] |
| 255 | |
| 256 | # Choices which are other types of Documents |
| 257 | if isinstance(value, (Document, EmbeddedDocument)): |
| 258 | if not any(isinstance(value, c) for c in choice_list): |
| 259 | self.error("Value must be an instance of %s" % (choice_list)) |
| 260 | # Choices which are types other than Documents |
| 261 | else: |
| 262 | values = value if isinstance(value, (list, tuple)) else [value] |
| 263 | if len(set(values) - set(choice_list)): |
| 264 | self.error("Value must be one of %s" % str(choice_list)) |
| 265 | |
| 266 | def _validate(self, value, **kwargs): |
| 267 | # Check the Choices Constraint |
no test coverage detected