![](/img/trans.png)
[英]Plone: custom edit form for dexterity content type with custom behavior on save
[英]Plone custom edit/add form using Dexterity/Grok
我正在尝试为我使用Dexterity类型构建的表单包创建自定义编辑/添加表单。 我在Dexterity Developer Manual部分中关注Plone开发人员文档中的Schema驱动类型教程。 到目前为止,我已成功创建了一个包含两种内容类型的Dexterity包:FAQ和Question。 我的FAQ Dexterity内容类型是一个容器,我的Question Dexterity内容类型只能添加到我的FAQ容器中。
常见问题内容类型 - FAQ.py
from product.faq import MessageFactory as _
from five import grok
from plone.dexterity.content import Container
from plone.directives import dexterity, form
from zope import schema
from zope import interface
from Acquisition import aq_inner
from Products.CMFCore.utils import getToolByName
from product.faq.question import IQuestion
class IFAQ(form.Schema):
""" Project FAQ Container """
class FAQ(Container):
grok.implements(IFAQ)
class View(grok.View):
""" FAQ View Class """
grok.context(IFAQ)
grok.require('zope2.View')
def questions(self):
""" Return a catalog search result of questions to show """
context = aq_inner(self.context)
catalog = getToolByName(context, 'portal_catalog')
return catalog(object_provides=IQuestion.__identifier__,
path='/'.join(context.getPhysicalPath()),
sort_on='sortable_title')
问题类型 - Question.py
from product.faq import MessageFactory as _
from five import grok
from plone.dexterity.content import Container
from plone.directives import dexterity, form
from zope import schema
from zope import interface
class IQuestion(form.Schema):
""" Project FAQ Question Type """
title = schema.TextLine(
title=_(u"Question"),
)
answer = schema.TextLine(
title=_(u"Answer"),
)
# Used to group questions into sections
section = schema.TextLine(
title=_(u"Section"),
)
class Question(Container):
grok.implements(IQuestion)
class Edit(grok.Form):
""" FAQ Question Edit Class """
grok.context(IQuestion)
grok.require('zope2.View')
我需要能够为添加和编辑视图自定义表单标记。 到目前为止,我已经能够创建一个没有功能的编辑视图。 如何将功能添加回我的表单?
edit.py
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
lang="en"
metal:use-macro="context/main_template/macros/master"
i18n:domain="product.faq">
<body>
<metal:main fill-slot="content-core">
<metal:content-core define-macro="content-core">
<h2>This is a Edit Form</h2>
<ul class="list-unstyled">
<li><strong>Plone's Title is: </strong><i tal:content="context/Title"></i></li>
<li><strong>Plone's Description is: </strong><i tal:content="context/Description"></i></li>
</ul>
<form class="form-horizontal clearfix" role="form">
<div class="form-group">
<label for="faqQuestion" class="col-lg-2 control-label">Question</label>
<div class="col-lg-10">
<input tal:attributes="value context/title" type="textfield" class="form-control" id="faqQuestion" placeholder="Enter a question">
</div>
</div>
<div class="form-group">
<label for="faqAnswer" class="col-lg-2 control-label">Answer</label>
<div class="col-lg-10">
<input tal:attributes="value context/answer" type="textfield" class="form-control" id="faqAnswer" placeholder="Enter a answer">
</div>
</div>
<div class="form-group">
<label for="faqSection" class="col-lg-2 control-label">Section</label>
<div class="col-lg-10">
<input tal:attributes="value context/section" type="textfield" class="form-control" id="faqSection" placeholder="Enter a grouping">
</div>
</div>
<div class="btn-group pull-right">
<a href="#" class="btn btn-primary">Save</a>
<a href="#" class="btn btn-danger">Cancel</a>
</div>
</form>
</metal:content-core>
</metal:main>
</body>
</html>
我的另一个问题是如何创建自定义添加视图? 当我点击添加我的网址指向http://localhost:8080/demo/faq/++add++product.faq.question
。 ++ add ++表示它是一个小部件吗?
提前致谢。
对于您的自定义敏捷添加/编辑表单,您可能需要阅读http://docs.plone.org/external/plone.app.dexterity/docs/advanced/custom-add-and-edit-forms中的dexterity文档。 HTML
请按照以下网址进行操作,我按照自定义添加和编辑视图进行操作,然后运行http://developer.plone.org/content/dexterity.html#custom-add-form-view
注意:它具有DefaultAddForm
, DefaultAddView
基类,用于自定义AddForm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.