我正在尝试为我使用Dexterity类型构建的表单包创建自定义编辑/添加表单。我正在关注Dexterity Developer Manual部分中Plone开发人员文档的Schema驱动类型教程。到目前为止,我已成功创建了一个包含两种内容类型的Dexterity包:FAQ和Question。我的FAQ 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 ++是否表示它是一个小部件?
提前致谢。
答案 0 :(得分:4)
对于您的自定义敏捷添加/编辑表单,您可能需要阅读http://docs.plone.org/external/plone.app.dexterity/docs/advanced/custom-add-and-edit-forms.html
中的敏捷文档答案 1 :(得分:0)
请仔细阅读以下网址,我按照自定义添加和修改视图进行操作,http://developer.plone.org/content/dexterity.html#custom-add-form-view
注意:自定义DefaultAddForm
DefaultAddView
,AddForm
基类