Plone技术论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 94|回复: 0

定制Dexterity的添加和编辑表单 [复制链接]

Rank: 9Rank: 9Rank: 9

发表于 2012-1-16 14:55:05 |显示全部楼层
Dexterity relies on ++add++yourcontent.type.name traverser hook defined in Products/CMFCore/namespace.py.
It will look up a multi-adapter with this expression:
if ti is not None:
    add_view = queryMultiAdapter((self.context, self.request, ti),
                                 name=ti.factory)
    if add_view is None:
        add_view = queryMultiAdapter((self.context, self.request, ti))


name parameter is portal_types id of your content type.
You can register such an adapter in configure.zcml
<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:browser="http://namespaces.zope.org/browser"
    >

    <adapter
        for="Products.CMFCore.interfaces.IFolderish
             Products.CMFDefault.interfaces.ICMFDefaultSkin
            plone.dexterity.interfaces.IDexterityFTI"
        provides="zope.publisher.interfaces.browser.IBrowserPage"
        factory=".flexicontent.AddView"
        name="your.app.flexiblecontent"
        />

</configure>


Warning

Overriding add_view_expr or add_view_expr_object in Dexterity factory type information to directly link to a view providedto be not possible. You can manually type Add view link in portal_types, but setting it through GenericSetup installercode is not possible.


Then you can inherit from proper plone.dexterity base classes:
from plone.dexterity.browser.add import DefaultAddForm, DefaultAddView

class AddForm(DefaultAddForm):


    def update(self):
        DefaultAddForm.update(self)

    def updateWidgets(self):
        """ """
        # Some custom code here

    def getBlockPlanJSON():
        return getBlockPlanJSON()

class AddView(DefaultAddView):
    form = AddForm


See also
Custom edit formExample:
from five import grok
from plone.directives import dexterity

class EditForm(dexterity.EditForm):

    grok.context(IFlexibleContent)

    def updateWidgets(self):
        """ """
        dexterity.EditForm.updateWidgets(self)

        # XXX: customize widgets here





招聘Python/Plone开发人员

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

Archiver|Plone技术论坛 ( 湘ICP备07003419 )

GMT+8, 2012-2-23 20:20 , Processed in 0.085878 second(s), 8 queries , Gzip On, Memcache On.

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部