2011/01/29

EEA Vocabulary Setup

了解 vocabulary 的運作原理後,可以參考 Products.EEAContentTypes 的設定範例,在 Products/EEAContentTypes/setup/vocabularies.py 檔案裡看得到變數設定值:
vocabs = {}
vocabs['themes'] = (
('default', 'Default'),
...
('various', 'Various other issues'),
('waste', 'Waste'),
('water', 'Water'),
)
在 Products/EEAContentTypes/setup/ConfigurationMethods.py 裡看得到設定方法:
def setupATVocabularies(self, portal):
""" Installs all AT-based Vocabularies """

from Products.ATVocabularyManager.config import TOOL_NAME \
as ATVOCABULARYTOOL
from vocabularies import vocabs

vkeys = vocabs.keys()
atvm = getToolByName(portal, ATVOCABULARYTOOL, None)
if atvm is None:
return

for vkey in vkeys:

if hasattr(atvm, vkey):
continue

print "adding vocabulary %s" % vkey

atvm.invokeFactory('SimpleVocabulary', vkey)
vocab = atvm[vkey]
for (ikey, value) in vocabs[vkey]:
vocab.invokeFactory('SimpleVocabularyTerm', ikey)
vocab[ikey].setTitle(value)
不過,ConfigurationMethods.py 裡用的 SetupWidget 是舊式方法,新版已改用 GenericSetup 方式安裝。另外,collective.realestatebroker 使用 unicode_vocabulary 來取代 SimpleVocabularycollective-docs 裡說明 vocabulary 的新式建立方式也和 Archetypes 不同,目前使用 dexterity 來搭配測試。

No comments: