python - 如何根据选择变量中的值将 PloneFormGen 重定向到页面?

标签 python plone plone-4.x ploneformgen

我在 Plone 4.3.3 中使用 PloneFormGen 1.7.12。我有一个很大的选择字段,其中包含大约 20 个名称。这是必需的。如果用户选择其中一个名字,它应该将它们发送到一个 Plone Page 模板,该模板有它们的说明。如果它选择任何其他页面,它应该向用户发送一封包含他们的表单结果的电子邮件,并将他们带到一个感谢页面。

我已经尝试使用 python 脚本执行此操作,但我所做的不起作用。脚本中的代码是:

REDIRECT = context.REQUEST.RESPONSE.redirect
URL=context.REQUEST.URL1 + '/'
FORM=context.REQUEST.form
school_name = context.REQUEST.form['school_name']

member = context.portal_membership.getAuthenticatedMember()
roles=member.getRolesInContext(context)

if school_name <> "Other-School not Listed":
    return False
else:
    return REDIRECT(URL + 'not_listed')

我将 python:here.school_redirect() 放在自定义表单操作覆盖中,但 URL 显示:

python:here.school_redirect()

页面显示“无法理解地址”

school_redirect 是python脚本的id not_listed 是Plone页面模板的id school_name 是选择字段的id

非常感谢任何建议。

乔比格勒

最佳答案

Custom Form Action 是一个简单的 StringField,没有 TALES 表达式字段。

这意味着您可以将 ./school_redirect 添加到 Custom Form Action 中,但是您会遇到其他问题,例如返回 False 将不起作用,无论如何你都需要重定向。您还可以绕过所有验证器和成功处理程序。

所以恕我直言,另一种方法可能更好:

<强>1。覆盖成功处理程序

自定义成功操作 FormFolder 上的字段。您可以添加单个表达式或 Python 脚本,它会返回正确的值。

字段说明:

Use this field in place of a thanks-page designation to determine final action after calling your action adapter (if you have one). You would usually use this for a custom success template or script. Leave empty if unneeded. Otherwise, specify as you would a CMFFormController action type and argument, complete with type of action to execute (e.g., "redirect_to" or "traverse_to") and a TALES expression. For example, "redirect_to:string:thanks-page" would redirect to 'thanks-page'.

您的 ./school_redirect 只需稍作改动即可适应此解决方案。不要重定向自己,只返回正确的 id(页面模板/ View /等)

<强>2。不要触发邮件适配器

为此,邮件适配器提供了一个名为执行条件的字段。

A TALES expression that will be evaluated to determine whether or not to execute this action. Leave empty if unneeded, and the action will be executed. Your expression should evaluate as a boolean; return True if you wish the action to execute. PLEASE NOTE: errors in the evaluation of this expression will cause an error on form display.

添加脚本或表达式,用于评估是否需要触发电子邮件。

您可以重用 ./school_redirect 脚本来编写表达式:python: here.school_redirect() != 'not_listed'/p>

关于python - 如何根据选择变量中的值将 PloneFormGen 重定向到页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34364509/

相关文章:

session - 如何导出Plone session 配置?

plone - 无法添加我的基于原型(prototype)的内容类型

plone - 在 Plone Site 设置中添加一个新的配置链接

python - 静态 css 文件和 xdv

python - 在创建新产品时,我在 plone4.3 上遇到错误 "No egg-info directory found "

python - 当我使用 plone.api content.create 查找结果时,结果为空

Python 2 OpenCV 2 - Convex Hull 关闭打开的 Canny Edge?

python - 如何在 Python 中将文本写在图像上,并在其上覆盖另一个图像?

python - 如何在 Django Admin 中实现计算模型属性的排序,而无需编写两次逻辑?

python - 训练 TensorFlow 预测总和