定制Dexterity的添加和编辑表单

定制Dexterity的添加和编辑表单
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>


[align=left]Warning[/align][align=left]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.[/align]
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





设置