【问题标题】:Plone custom edit/add form using Dexterity/Grok使用 Dexterity/Grok 克隆自定义编辑/添加表单
【发布时间】:2013-10-10 13:18:21
【问题描述】:

我正在尝试为我使用 Dexterity 类型构建的表单包创建自定义编辑/添加表单。我正在关注Dexterity Developer Manual 部分中 Plone 开发人员文档中的模式驱动类型教程。到目前为止,我已经成功创建了一个包含两种内容类型的 Dexterity 包:FAQ 和 Question。我的 FAQ Dexterity 内容类型是一个容器,我的 Question Dexterity 内容类型只能添加到我的 FAQ 容器中。

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++ 是否表示它是一个小部件?

提前致谢。

【问题讨论】:

  • 请参阅++add++-traversal-adaptercustomize add-formcustomize edit-form 的文档并告诉我们,如果您可以继续使用它们。信息:文档分布在不同的地方,但我读过,有计划很快整合它们:)
  • @IdaEbkes 我查看了提供的文档,但还没有弄清楚。我已经尝试过 dexterity.AddForm 和 gork.form 方法。就像我之前所说的,我可以显示自定义编辑表单,但不能显示自定义添加表单。
  • 您似乎没有关注文档。理想情况下,您会这样做,描述每个步骤以及在哪一点上什么不起作用。也许您也想解释用例。问候,艾达

标签: plone dexterity grok


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    注意:它有 DefaultAddForm, DefaultAddView 自定义基类 AddForm

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多