2013-07-29 25 views
0

我有一個Python的腳本,它返回返回基於上下文的,動態生成的簡單列表:動態詞彙表的Grokless方式?

def myVocabMethod(self): 
    mylist = ['a','list','apart'] 
    # do sth dynamic 

    return mylist 

我想結果傳遞給的詞彙屬性看s.th選擇場。像這樣:

atapi.StringField('theField' 
    vocabulary=.myPythonScript.myVocabMethod(), 
    (...) 
), 

如何將腳本結果和vocab值粘合在一起?

我發現的文檔總是需要Grok。此外,它只是一個簡單的列表,沒有i18n或其他更復雜的功能需要。

+0

你能更具體嗎?什麼樣的動態詞彙,什麼樣的領域等?顯示代碼。 –

+0

@LennartRegebro:我還沒有寫出任何具體代碼將它粘合在一起,因爲我還沒有找到一個無怨無悔的例子。用我指的文檔更新了任務。 –

+0

不,但合理的,你有某種具體的代碼,你想使用詞彙表架構或形式或內容類型或什麼的。這是原型嗎?靈巧? PloneFormGen?都不是?當你沒有grok時,你實際上在問怎麼做'@ grok.provider()'?這似乎是唯一的grok部分。 –

回答

1

的帖子,在那裏我找到了我一直在尋找這是一個: http://www.universalwebservices.net/web-programming-resources/zope-plone/dynamic-vocabularies-in-plone-archetypes/

,並在官方文檔在這裏被引用: http://developer.plone.org/content/archetypes/fields.html#dynamic-vocabularies

對於任何人誰可能會感興趣,這是代碼:

from Acquisition import aq_parent 
from Products.Archetypes import atapi 
from Products.Archetypes.public import DisplayList 

YourArchetypeSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema((

atapi.StringField(
    'somefieldname', 
    vocabulary = yourVocabulary, 
    ), 

)) 

class YourArchetype(base.ATCTContent): 

    def yourVocabulary(self): 
     dl = DisplayList() 
     # We can do something context-based here, 
     # f.e. get all Events in parent-folder: 
     eventlist = aq_parent(self).contentValues(filter={'portal_type' : 'Event'}) 
     for event in eventlist: 
      dl.add(event['id'], event['title']) 
     return dl 

atapi.registerType(YourArchetype, PROJECTNAME)