Skip to content. | Skip to navigation

Personal tools

Navigation

You are here: Home / Tips / Vocabulary

Vocabulary

分成 Static Vocabulary, Dynamic Source, Parameterised Source, Named Vocabulary 不同類型,系統透過 plone.app.vocabularies 提供常用的辭典集。 @vocabularies restapi endpoint for anonymous to access

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.

程式碼範例 collective.glossary

    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'),
)

collective.z3cform.chosen

Getting Vocabulary Values in a loop

使用 UUID 查詢 Catalog

依顯示需要決定不同長度的關鍵字 非必填的動態辭彙表

empty_first_item custom_first_empty_item

避免 collective.elephantvocabulary 相依關係

tile edit view wrong context

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