Plone 使用灵巧度/Grok定制编辑/添加表单

Plone 使用灵巧度/Grok定制编辑/添加表单,plone,dexterity,grok,Plone,Dexterity,Grok,我正在尝试为我的表单包创建一个自定义的编辑/添加表单,该表单包是我使用灵巧类型构建的。在本节中,我将学习关于Plone开发人员文档的模式驱动类型教程。到目前为止,我已经成功地创建了一个包含两种内容类型的灵巧包:FAQ和问题。我的FAQ灵巧性内容类型是一个容器,我的问题灵巧性内容类型只能添加到我的FAQ容器中 常见问题解答内容类型-FAQ.py 问题类型-Question.py 我需要能够为添加和编辑视图自定义表单标记。到目前为止,我已经能够创建一个编辑视图,在功能上没有任何问题。如何将函数添加回

我正在尝试为我的表单包创建一个自定义的编辑/添加表单,该表单包是我使用灵巧类型构建的。在本节中,我将学习关于Plone开发人员文档的模式驱动类型教程。到目前为止,我已经成功地创建了一个包含两种内容类型的灵巧包:FAQ和问题。我的FAQ灵巧性内容类型是一个容器,我的问题灵巧性内容类型只能添加到我的FAQ容器中

常见问题解答内容类型-FAQ.py

问题类型-Question.py

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

编辑.py


这是一个编辑表单
  • Plone的标题是:
  • Plone的描述是:
问题 答复 部分
我的另一个问题是如何创建自定义添加视图?单击“将我的url点添加到
http://localhost:8080/demo/faq/++添加++产品.常见问题解答.问题
。++add++是否表示它是一个小部件


提前感谢。

对于您的自定义灵巧添加/编辑表单,您可能希望阅读位于的灵巧文档对于您的自定义灵巧添加/编辑表单,您可能希望阅读位于的灵巧文档请浏览以下url,我在自定义添加和编辑视图中遵循了它,并且它起到了作用


注意:它有
DefaultAddForm
DefaultAddView
自定义
AddForm

的基类,请浏览下面的url,我在自定义添加和编辑视图中遵循了它,它成功了


注意:它有
DefaultAddForm
DefaultAddView
自定义
AddForm

的基类请参阅文档,并告诉我们是否可以继续使用它们。信息:这些文档分布在不同的地方,但我读到了,有计划很快将它们合并:)@IdaEbkes我已经查看了提供的文档,但还没有弄清楚。我尝试过dexterity.AddForm和gork.form方法。正如我之前所说,我可以让我的自定义编辑表单显示,但不是自定义添加表单。看起来你没有遵循文档。理想情况下,您可以这样做,描述每一步以及在哪一点上哪些不起作用。也许你也想解释一下这个用例。您好,我看了文件,并告诉我们,您是否可以继续。信息:这些文档分布在不同的地方,但我读到了,有计划很快将它们合并:)@IdaEbkes我已经查看了提供的文档,但还没有弄清楚。我尝试过dexterity.AddForm和gork.form方法。正如我之前所说,我可以让我的自定义编辑表单显示,但不是自定义添加表单。看起来你没有遵循文档。理想情况下,您可以这样做,描述每一步以及在哪一点上哪些不起作用。也许你也想解释一下这个用例。你好,艾达
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')
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')
<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>