1

我正在尝试为我使用 Dexterity 类型构建的表单包创建自定义编辑/添加表单。我正在关注Dexterity 开发人员手册部分的 Plone 开发人员文档中的模式驱动类型教程。到目前为止,我已经成功创建了一个包含两种内容类型的 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')

我需要能够为添加和编辑视图自定义表单标记。到目前为止,我已经能够创建一个没有功能的编辑视图。如何将功能添加回我的表单?

编辑.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>

我的另一个问题是如何创建自定义添加视图?当我点击添加我的 url 点到http://localhost:8080/demo/faq/++add++product.faq.question. ++add++ 是否表示它是一个小部件?

提前致谢。

4

2 回答 2

4

对于您的自定义敏捷添加/编辑表单,您可能需要阅读http://docs.plone.org/external/plone.app.dexterity/docs/advanced/custom-add-and-edit-forms 上的敏捷文档。 html

于 2013-10-11T18:31:15.910 回答
0

请通过以下网址,我按照它进行自定义添加和编辑视图,它工作http://developer.plone.org/content/dexterity.html#custom-add-form-view

注意:它有 自定义DefaultAddFormDefaultAddView基类AddForm

于 2014-01-20T14:29:21.190 回答