gpt4 book ai didi

plone - 我可以在 Plone portlet 上使用 z3c.form 而不是 zope.formlib 吗?

转载 作者:行者123 更新时间:2023-12-04 16:32:29 25 4
gpt4 key购买 nike

考虑到我有一个普通的 ZopeSkel plone3_portlet formlib 生成的包,我需要做哪些修改? IE:

  • 我应该从哪些类继承?
  • 我必须提供哪些 Hook ?

  • 我可以一直使用它,包括 Five.grok 和 plone.directives.form 吗?

    最佳答案

    是的,你可以这样做,你需要的是添加/编辑表单......这是我为一个 Jarn 项目所做的,你可以像使用它们的 formlib 等效项一样使用 AddForm 和 EditForm:

    from Acquisition import aq_parent, aq_inner
    from plone.app.portlets import PloneMessageFactory as _
    from plone.app.portlets.browser.interfaces import IPortletAddForm
    from plone.app.portlets.browser.interfaces import IPortletEditForm
    from plone.app.portlets.interfaces import IPortletPermissionChecker
    from z3c.form import button
    from z3c.form import form
    from zope.component import getMultiAdapter
    from zope.interface import implements


    class AddForm(form.AddForm):
    implements(IPortletAddForm)

    label = _(u"Configure portlet")

    def add(self, object):
    ob = self.context.add(object)
    self._finishedAdd = True
    return ob

    def __call__(self):
    IPortletPermissionChecker(aq_parent(aq_inner(self.context)))()
    return super(AddForm, self).__call__()

    def nextURL(self):
    addview = aq_parent(aq_inner(self.context))
    context = aq_parent(aq_inner(addview))
    url = str(getMultiAdapter((context, self.request),
    name=u"absolute_url"))
    return url + '/@@manage-portlets'

    @button.buttonAndHandler(_(u"label_save", default=u"Save"), name='add')
    def handleAdd(self, action):
    data, errors = self.extractData()
    if errors:
    self.status = self.formErrorsMessage
    return
    obj = self.createAndAdd(data)
    if obj is not None:
    # mark only as finished if we get the new object
    self._finishedAdd = True

    @button.buttonAndHandler(_(u"label_cancel", default=u"Cancel"),
    name='cancel_add')
    def handleCancel(self, action):
    nextURL = self.nextURL()
    if nextURL:
    self.request.response.redirect(nextURL)
    return ''


    class EditForm(form.EditForm):
    """An edit form for portlets.
    """

    implements(IPortletEditForm)

    label = _(u"Modify portlet")

    def __call__(self):
    IPortletPermissionChecker(aq_parent(aq_inner(self.context)))()
    return super(EditForm, self).__call__()

    def nextURL(self):
    editview = aq_parent(aq_inner(self.context))
    context = aq_parent(aq_inner(editview))
    url = str(getMultiAdapter((context, self.request),
    name=u"absolute_url"))
    return url + '/@@manage-portlets'

    @button.buttonAndHandler(_(u"label_save", default=u"Save"), name='apply')
    def handleSave(self, action):
    data, errors = self.extractData()
    if errors:
    self.status = self.formErrorsMessage
    return
    changes = self.applyChanges(data)
    if changes:
    self.status = "Changes saved"
    else:
    self.status = "No changes"

    nextURL = self.nextURL()
    if nextURL:
    self.request.response.redirect(self.nextURL())
    return ''

    @button.buttonAndHandler(_(u"label_cancel", default=u"Cancel"),
    name='cancel_add')
    def handleCancel(self, action):
    nextURL = self.nextURL()
    if nextURL:
    self.request.response.redirect(nextURL)
    return ''

    关于plone - 我可以在 Plone portlet 上使用 z3c.form 而不是 zope.formlib 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5174905/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com