Vocabulary
在 plone.app.vocabulary 利用 zope.schema.vocabulary 實作了基本辭彙當作延伸開發的範例。
Country ISO3166 collective.address
原理與建立方式
選項式欄位的建立方式有兩大類。單選欄位 Selection Field 使用 Choice 欄位型別,範例是 myChoice = schema.Choice(...)。多選欄位 MultiSelection Field 可以使用 List、Tuple、Set、Frozenset 欄位型別,再搭配 value_type 參數,範例是 myList = schema.List(..., value_type=schema.Choice(...))。
Choice 型別需要指定一種選項來源:
- values can be used to give a list of static values;
- source can be used to refer to an IContextSourceBinder or ISource instance;
- vocabulary can be used to refer to an IVocabulary instance or (more commonly) a string giving the name of an IVocabularyFactory named utility.
enabled_content_types = schema.List( title=_(u'Enabled Content Types'), description=_(u'Only objects of these content types will display glossary terms.'), required=False, default=DEFAULT_ENABLED_CONTENT_TYPES, # we are going to list only the main content types in the widget value_type=schema.Choice( vocabulary=u'collective.glossary.PortalTypes'), )
Getting Vocabulary Values in a loop
empty_first_item custom_first_empty_item
避免 collective.elephantvocabulary 相依關係
Provide Vocabulary for a SubTree
@provider(IFormFieldProvider) class ISpnsorVocabularyDefinition(model.Schema): """Behavior providing fields to define a sponsor vocabulary """
Complex Vocabulary and Multi-Select Fileds
MasterSelectField Vocabulary plone.formwidget.masterselect
Sample Codes: fourdigits.tracker collective.weather
def update(self): weather_utility = getUtility(IWeatherUtility) factory = getUtility( IVocabularyFactory, name='collective.weather.Locations') vocab = factory(self.context) self.current_city = None if self.data.location in vocab: location = vocab.by_value[self.data.location] self.current_city = {'location_id': location.value, 'name': location.title} self.weather_info = None if not self.current_city is None: weather_utility.update_weather_info(self.current_city['location_id']) self.weather_info = weather_utility.get_weather_info(self.current_city)
plone.schemaeditor TTW: collective.taxonomy , SKOS format Use Context Language to Find Index Tree Editor by a ReactJS application to edit the taxonomy
Sortable Vocabulary Image Scales Vocabulary
相關模組比較 ATVocabularyManager With EEA.FacetedNavigation http://community.plone.org/t/vocabulary-data-fetching/7410
class DaoTypesVocabulary(object): """Vocabulary Factory for Dao Types """ implements(IVocabularyFactory) def __call__(self, *args, **kwargs): dao_types = {'DaoFaTan': u'DaoFaTan', 'KeYi': u'KeYi', 'DaoShi': u'DaoShi'} dao_terms = [SimpleTerm(i[0], i[0], i[1]) for i in dao_types] return SimpleVocabulary(dao_terms)
ConstraintNotSatisfied migration the related vocabulary values (the UIDs of the related objects) are not yet available