跳转到主要内容

为PloneFormGen提供Silverpop集成的插件

项目描述

为PloneFormGen提供Silverpop企业通讯集成的插件。

添加了一个FormSilverpopAdapter,可用于创建通讯录注册表单,以便将收件人添加到Silverpop通讯录。

支持简单的“同意”/“不同意”,意味着用户可以通过勾选布尔字段来订阅通讯录,通过取消勾选布尔字段来取消订阅。

重新“同意”尚未实现。

使用Silverpop Python API

要求

  • Products.PloneFormGen

  • Products.DataGridField

  • silverpop

链接

变更日志

0.9 (2009-05-18)

  • 修改日志级别,现在日志记录到WARNING和ERROR [hplocher]

0.8 (2009-05-14)

  • 处理URLError、HTTPError异常 [hplocher]

  • 如果发生错误,则显示错误信息 [hplocher]

  • 修复问题(没有自定义字段的形式不会导致Silverpop API请求) [hplocher]

0.7 (2009-05-13)

  • 支持已退订的收件人选择加入

  • 使用Silverpop的opt_in_recipient

  • 需要silverpop >= 0.4

0.6 (2009-05-12)

  • 需要silverpop Python包

  • 重构,使用silverpop包中的silverpop API方法 [hplocher]

0.5 (2009-05-11)

  • 添加对opt-in/opt-out功能的支持

  • 定义新策略:如果表单包含ID为'silverpop_opt_in'的字段,我们将其用作控制选择加入。如果该字段为True,则用户将被添加到通讯录。如果它为False,则用户将退订通讯录(例如,使用布尔字段复选框,选中=1,未选中=0) [hplocher]

  • 解析silverpop的xml响应 [hplocher]

  • 重构测试以创建美观的xml输出 [hplocher]

0.4 (2009-05-06)

  • 移除FormSilverpopAdapter的工作流程 [hplocher]

  • 添加定义自定义'field_id' -> 'silverpop_column_name'映射的功能 [hplocher]

  • 在FormSilverPopAdapter中添加映射网格

    (id(只读), 标题(只读), silverpop API密钥)用于配置映射 [hplocher]

  • 需要DataGridField [hplocher]

0.3 (2009-04-08)

  • 新策略:按前缀过滤数据字段。我们只使用以COLUMN_NAME_PREFIX(silverpop_)开头的字段名。这使我们免于字段名与plone ID冲突。此外,我们已定义了一个映射表,用于需要按字面意思使用的SilverPop API列名 - COLUMN_MAPPING。 [seletz]

  • 删除CONFIRMATION逻辑 - 这可以在PFG中更好地处理 [seletz]

0.2 (2009-04-08)

  • 添加Unicode支持,修复#1 [Hans-Peter Locher]

0.1 (2009-04-02)

  • 初始版本 [Hans-Peter Locher]

简介

此测试展示了如何添加PFG表单文件夹。我们还添加了自定义的FormSilverpopAdapter,对其进行配置,并显示实际发送的XML。

设置

首先,我们必须进行一些设置。我们使用Five附带的testbrowser,因为它提供了适当的Zope 2集成。尽管如此,大部分文档都在底层的zope.testbrowser包中

>>> from Products.Five.testbrowser import Browser
>>> browser = Browser()
>>> portal_url = self.portal.absolute_url()

以下是在编写和调试testbrowser测试时有用的内容。它使我们能够查看错误_log中的所有错误消息

>>> self.portal.error_log._ignored_exceptions = ()

有了这些,我们可以转到门户首页并登录。我们将使用PloneTestCase的默认用户进行此操作

>>> from Products.PloneTestCase.setup import portal_owner, default_password

>>> browser.open(portal_url)

我们有登录端口,所以让我们使用它

>>> browser.getControl(name='__ac_name').value = portal_owner
>>> browser.getControl(name='__ac_password').value = default_password
>>> browser.getControl(name='submit').click()

在此,我们设置登录表单上的字段值,然后模拟提交点击。

我们还需要设置我们想要的角色

>>> self.setRoles(['Member', 'Manager'])

我们将monkeypatch silverpop以禁止向silverpop发送请求,并仅显示测试输出

>>> import silverpop
>>> def opt_in_recipient(api_url, list_id, email, columns=[]):
...     """opt in a recipient to a list (only email key supported)
...     api_url, list_id, email are required, optionally
...     takes a list of dicts to define additional columns like
...     [{'column_name':'State', 'column_value':'Germany'},]
...     returns True or False
...     """
...     print '**********silverpop-method***************************'
...     print 'opt_in_recipient(api_url, list_id, email, columns=[])'
...     print '**********attributes*********************************'
...     print 'api_url: %s' % api_url
...     print 'list_id: %s' % list_id
...     print 'email: %s' % email
...     print 'columns: %s' % columns
...     return True

>>> silverpop.opt_in_recipient = opt_in_recipient

>>> def opt_out_recipient(api_url, list_id, email):
...     """opt out a recipient from a list
...     api_url, list_id, email are required
...     returns True or False
...     """
...     print '**********silverpop-method****************'
...     print 'opt_out_recipient(api_url, list_id, email)'
...     print '**********attributes**********************'
...     print 'api_url: %s' % api_url
...     print 'list_id: %s' % list_id
...     print 'email: %s' % email
...     return True

>>> silverpop.opt_out_recipient = opt_out_recipient

我们还定义了一个FakeRequest类来定义我们的请求,其中只包含一个表单

>>> class FakeRequest(dict):
...   def __init__(self, **kwargs):
...     self.form = kwargs

添加内容

添加新的表单文件夹

>>> browser.getLink('Form Folder').click()
>>> browser.getControl('Title').value = 'testform'
>>> browser.getControl('Save').click()

>>> 'testform' in browser.contents
True

转到新的表单文件夹

>>> browser.getLink('testform').click()

我们使用“添加新”菜单添加新内容项

>>> browser.getLink('Add new').click()

然后我们选择要添加的项目类型。在这种情况下,我们选择“FormSilverpopAdapter”并点击“添加”按钮以进入添加表单

>>> browser.getControl('FormSilverpopAdapter').click()
>>> browser.getControl(name='form.button.Add').click()
>>> 'FormSilverpopAdapter' in browser.contents
True

现在我们填写表单并提交

>>> browser.getControl(name='title').value = 'testadapter'
>>> browser.getControl('Silverpop API URL').value = 'http://url.com'
>>> browser.getControl('Silverpop List Id').value = '1'
>>> browser.getControl('Save').click()
>>> 'Changes saved' in browser.contents
True

我们在测试表单中添加了一个新的“FormSilverpopAdapter”内容项

字段名策略

我们强制实施以下策略,关于我们通过它们的API发送到SilverPop的字段名

  • 字段名必须以公共前缀开始:“silverpop_”

  • 必须有一个字段“silverpop_email”

  • 可以有一个额外的字段“silverpop_opt_in”来控制选择加入/退订

我们有一个转换函数来完成这项工作

>>> from collective.pfg.silverpop.utilities import transform_column_name
>>> transform_column_name("silverpop_foo")
'foo'
>>> transform_column_name("no_prefix") is None
True

onSuccess

在提交表单时,我们的FormSilverpopAdapter的onSuccess方法将被调用。

我们想要直接访问我们的测试表单和测试适配器

>>> self.testform = self.portal.testform
>>> self.testadapter = self.portal.testform.testadapter

我们在表单内部创建一些字段。

首先,我们创建应该由我们的“FormSilverpopAdapter”考虑的字段。

特殊的“sivlerpop_email”字段(此字段具有固定的映射)

>>> self.testform.invokeFactory('FormStringField', 'silverpop_email', title='Email')
'silverpop_email'

用于插入名称的字段

>>> self.testform.invokeFactory('FormStringField', 'silverpop_name', title='Name')
'silverpop_name'

我们还创建了一个杂项字段,尽管它与相同的格式,但不应该被视为。

>>> self.testform.invokeFactory('FormStringField', 'credits_to_admin', \
... title='Give your credits to the admin of the site')
'credits_to_admin'

用户定义的映射

我们提供了定义从字段ID到Silverpop API密钥的映射的能力。

无映射

首先,我们检查在未更改映射时会发生什么。

我们转到“FormSilverpopAdapter”的编辑表单

>>> browser.open(portal_url+'/testform/testadapter/edit')

当前的映射应只包含一个记录(包含id、标题、Silverpop API密钥列),因此我们检查所有列。

id

>>> browser.getControl(name='mapping.id:records').value
'silverpop_name'

标题

>>> browser.getControl(name='mapping.title:records').value
'Name'

silverpop api密钥

>>> browser.getControl(name='mapping.silverpop api key:records', index=0).value
''

我们设置字段列表

>>> fields = [self.testform.silverpop_email, \
... self.testform.silverpop_name, self.testform.credits_to_admin,]

我们设置一个包含用户输入的最小请求

>>> request = FakeRequest(silverpop_email='x@x.com', silverpop_name='Hans', \
... credits_to_admin='I like the high availability')

我们现在调用适配器的onSuccess方法

>>> self.testadapter.onSuccess(fields,request)
**********silverpop-method***************************
opt_in_recipient(api_url, list_id, email, columns=[])
**********attributes*********************************
api_url: http://url.com
list_id: 1
email: x@x.com
columns: [{'column_value': 'Hans', 'column_name': 'name'}]
自定义映射

现在,我们检查更改映射时会发生什么。我们希望将“FIRST NAME”用作silverpop的列,对于“silverpop_name”字段。

我们转到“FormSilverpopAdapter”的编辑表单

>>> browser.open(portal_url+'/testform/testadapter/edit')

我们更改映射中的值

>>> browser.getControl(name='mapping.silverpop api key:records', index=0).value = 'FIRST NAME'
>>> browser.getControl('Save').click()

字段列表仍然是相同的。

我们设置一个包含用户输入的最小请求

>>> request = FakeRequest(silverpop_email='x@x.com', silverpop_name='Hans', \
... credits_to_admin='I like the high availability')

我们现在调用适配器的onSuccess方法

>>> self.testadapter.onSuccess(fields,request)
**********silverpop-method***************************
opt_in_recipient(api_url, list_id, email, columns=[])
**********attributes*********************************
api_url: http://url.com
list_id: 1
email: x@x.com
columns: [{'column_value': 'Hans', 'column_name': 'FIRST NAME'}]

同意/不同意

我们在表单中创建了一个特殊ID为“silverpop_opt_in”的布尔字段

>>> self.testform.invokeFactory('FormBooleanField', 'silverpop_opt_in', \
... title='Yes I want to get the newsletter')
'silverpop_opt_in'

此字段不应出现在testadapter的映射网格中。

我们转到“FormSilverpopAdapter”的编辑表单

>>> browser.open(portal_url+'/testform/testadapter/edit')

当前的映射仍然只包含一个记录,因此我们检查id列

>>> browser.getControl(name='mapping.id:records').value
'silverpop_name'
同意

用户想要获取通讯稿。选中的布尔字段将在请求中导致“True”。我们设置一个包含用户输入的最小请求

>>> request = FakeRequest(silverpop_email='x@x.com', silverpop_name='Hans', \
... silverpop_opt_in='True')

字段列表现在如下所示

>>> fields = [self.testform.silverpop_email, self.testform.silverpop_name, \
... self.testform.silverpop_opt_in]

我们现在调用适配器的onSuccess方法

>>> self.testadapter.onSuccess(fields,request)
**********silverpop-method***************************
opt_in_recipient(api_url, list_id, email, columns=[])
**********attributes*********************************
api_url: http://url.com
list_id: 1
email: x@x.com
columns: [{'column_value': 'Hans', 'column_name': 'FIRST NAME'}]
不同意

用户不想获取通讯稿,或者不再想获取。未选中的布尔字段将在请求中导致“False”。

我们设置一个包含用户输入的最小请求

>>> request = FakeRequest(silverpop_email='x@x.com', silverpop_name='Hans', \
... silverpop_opt_in='False')

字段列表仍然是相同的。

我们现在调用适配器的onSuccess方法

>>> self.testadapter.onSuccess(fields,request)
**********silverpop-method****************
opt_out_recipient(api_url, list_id, email)
**********attributes**********************
api_url: http://url.com
list_id: 1
email: x@x.com

贡献者

Hans-Peter Locher,作者Stefan Eletzhofer

下载

项目详细信息


下载文件

下载您平台上的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

collective.pfg.silverpop-0.9.zip (45.5 kB 查看散列)

上传时间

支持者:

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面