TypedField subclass for VocabString fields.
| 43 | |
| 44 | |
| 45 | class VocabField(fields.TypedField): |
| 46 | """TypedField subclass for VocabString fields.""" |
| 47 | |
| 48 | def __init__(self, *args, **kwargs): |
| 49 | """Intercepts the __init__() call to TypedField. |
| 50 | |
| 51 | Set the type that will be used in from_dict and from_obj calls to |
| 52 | :class:`VocabString`. |
| 53 | |
| 54 | Set the type that will be used in ``__set__`` for casting as the |
| 55 | original ``type_`` argument, or :class:`VocabString` if no `type_` |
| 56 | argument was provided. |
| 57 | |
| 58 | """ |
| 59 | super(VocabField, self).__init__(*args, **kwargs) |
| 60 | self.factory = VocabFactory # force this factory |
| 61 | |
| 62 | if self._unresolved_type is None: |
| 63 | self.type_ = VocabString |
| 64 | |
| 65 | self._listfunc = partial(VocabList, type=self._unresolved_type) |
| 66 | |
| 67 | def check_type(self, value): |
| 68 | return isinstance(value, VocabString) |
| 69 | |
| 70 | |
| 71 | class VocabFactory(entities.EntityFactory): |
no outgoing calls
no test coverage detected