【问题标题】:Plone: custom variable in content rulePlone:内容规则中的自定义变量
【发布时间】:2017-04-05 17:20:31
【问题描述】:

我定义了一个敏捷内容类型 myaddon.subscriber(订阅者 = 活动参与者)。

我添加了一个内容规则,以便在订阅者获得批准时发送电子邮件(工作流程状态更改为此)。

每个订阅者都有一个电子邮件地址(电子邮件 - 字段)。

在“编辑邮件操作”表单中,我看到我可以在 Email recipients (Required) The email where you want to send this message. To send it to different email addresses, just separate them with , 中使用像 ${user_email} 这样的变量

这是有效的。在我的情况下,user_email 是登录用户的电子邮件 - 批准参与者的人。当状态改变时发送消息。完美。

我需要定义一个变量${subscriber_email},它将具有 myaddon.subscriber.email 值。我怎样才能做到这一点?我试图找到一个例子。那么,如何使用当前更改对象(订阅者)的字段(电子邮件)作为此 Mail Action 中的变量?

【问题讨论】:

  • 您在我们的论坛community.plone.org(更多的眼球)上发布问题可能会更好,尽管我会在论坛上发布您问题的链接。

标签: plone plone-4.x


【解决方案1】:

您可以使用 plone.stringinterp 1.0.14+ 中的IContextWrapper

>>> new_context = IContextWrapper(context)(
...     email=u"subscriber@example.com"
... )

>>> class SubscriberEmailSubstitution(BaseSubstitution):
...     def safe_call(self):
...         return self.wrapper.email

>>> sm = getGlobalSiteManager()
>>> sm.registerAdapter(SubscriberEmailSubstitution, (Interface, ), IStringSubstitution, name=u"subscriber_email")

>>> getAdapter(new_context, IStringSubstitution, 'subscriber_email')()
u'subscriber@example.com'

进口:

>>> from zope.interface import Interface
>>> from plone.stringinterp.interfaces import IStringSubstitution
>>> from plone.stringinterp.interfaces import IStringSubstitutionInfo
>>> from zope.component import getGlobalSiteManager, getAdapter
>>> from plone.stringinterp.adapters import BaseSubstitution
>>> from plone.stringinterp.interfaces import IContextWrapper

查看更多 stringinterp doctests

另请参阅eea.pdf 插件中的完整示例。

【讨论】:

    猜你喜欢
    • 2017-07-14
    • 2021-04-23
    • 1970-01-01
    • 2021-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多