2015-02-06 31 views
1

在vanilla Plone 4.3.3站點(Ubuntu 14.04.1LTS上的統一安裝程序)以及使用zopeskel和paster更新buildout.cfg鍋爐板的東西,運行擴建,我成功地在我的src文件夾中創建了一個靈巧包:Plone 4.3.x - grokcore.view - UserWarning:配置後發現以下未關聯模板

$ cd src 
$ ../bin/zopeskel dexterity my.package 

更新buildout.cfg(添加my.package到蛋節和src/my.package到開發部分)之後並運行構建,我添加到我的新包內容:

$ cd my.package 
$ ../../bin/paster addcontent dexterity_content 

我所謂的新的內容類型MYTYPE,導致mytype.py,一個模板文件夾,名爲mytype_templates等

重新啓動的Plone和....到目前爲止,一切都很好....

然後,添加模板的mytype_templates文件夾:

add.pt 
edit.pt 
view.pt 

在mytype.py文件我加了所有必要的進口,架構定義

Class Imytype(form.Schema, IImageScaleTraversable): 
    .... 
    .... 

,等,等,顯然也視圖,添加和編輯類:

class View(dexterity.DisplayForm): 
    grok.context(Imytype) 
    grok.require('zope2.View') 

    # Disable turn fieldsets to tabs behavior 
    enable_form_tabbing = False 

    def update(self): 
     super(View, self).update() 


class Add(dexterity.AddForm): 
    grok.name('my.package.mytype') 

    # Disable turn fieldsets to tabs behavior 
    enable_form_tabbing = False 

    def __init__(self, context, request): 
     super(Add, self).__init__(context, request) 
    ...... 
    ...... 

class Edit(dexterity.EditForm): 
    grok.context(Imytype) 

    # Disable turn fieldsets to tabs behavior 
    enable_form_tabbing = False 

    def update(self): 
     super(Edit, self).update() 
    ...... 
    ...... 

當我重新啓動在前臺模式我的Plone站點中,我得到了以下信息:

2015-02-06 12:52:41 INFO ZServer HTTP server started at Fri Feb 6 12:52:41 2015 
Hostname: 0.0.0.0 
Port: 8080 
/home/Plone434_site/buildout-cache/eggs/grokcore.view-2.8-py2.7.egg/grokcore/view/templatereg.py:261: UserWarning: Found the following unassociated template after configuration: /home/Plone434_site/zinstance/src/my.package/my/package/mytype_templates/edit.pt 
    warnings.warn(msg, UserWarning, 1) 
/home/Plone434_site/buildout-cache/eggs/grokcore.view-2.8-py2.7.egg/grokcore/view/templatereg.py:261: UserWarning: Found the following unassociated template after configuration: /home/Plone434_site/zinstance/src/my.package/my/package/mytype_templates/add.pt 
    warnings.warn(msg, UserWarning, 1) 
2015-02-06 12:52:46 INFO Zope Ready to handle requests 

看似神交成功拿起view.pt,但不add.pt和edit.pt
這可以通過自定義模板來確認。 view.pt的更改呈現正常,對add.pt和edit.pt的更改沒有結果。由於add.pt和edit.pt沒有得到保護,Plone回到默認的敏捷模板上。

我發現了一個變通通過添加以下內容:

.... 
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile 
.... 

,並添加類:

template = ViewPageTemplateFile('mytype_templates/add.pt') 

,並編輯類:

template = ViewPageTemplateFile('mytype_templates/edit.pt') 

顯然,上面列出的錯誤消息仍然存在,但至少可以工作,我可以自定義add.pt和edit.pt. 儘管我可以接受這種解決方法,但我想知道爲什麼只有view.pt被grokked,而不是add.pt和edit.pt. 請注意,使用Plone 4.3.1,4.3.2,4.3.3和4.3.4也會重複這種(奇怪的?)行爲。

有什麼建議嗎?

回答

0

您必須聲明name,context,layerschema的意見;使用類似這樣(注意grok.layer方法,也許你錯過了它):

class AddForm(dexterity.AddForm): 
    grok.name('my.package.mytype') 
    grok.layer(Imylayer) 
    grok.context(Imytype) 
    schema = Imytype 

    def update(self): 
     super(AddForm, self).update() 
     ... 


class EditForm(dexterity.EditForm): 
    grok.context(Imytype) 
    grok.layer(Imylayer) 
    schema = Imytype 

    def update(self): 
     super(EditForm, self).update() 
     ... 

或者你可以跳過使用神交的根本,並通過ZCML註冊的一切。

可以在collective.nitf包中找到此示例。有a branch using Groka pull request removing it