gpt4 book ai didi

plone - 使用 Plone Form Gen 创建事件

转载 作者:行者123 更新时间:2023-12-04 15:00:34 27 4
gpt4 key购买 nike

我正在尝试使用 Plone Form Gen 创建一个事件内容类型。I have been using this tutorial为此。

使用添加新...菜单创建事件内容类型时,您需要填写两个字段:开始 结束 事件的日期,我希望我的表单从这些字段中提取信息并将其应用于我用来创建它的事件内容类型。

我所理解的问题用下面的例子来描述:

自定义脚本适配器脚本包含以下内容:

obj.setDescription(form['replyto'])

我可以看到它从以下内容中获取事件内容类型描述的内容:
<input id="replyto" class="" type="text" size="30" name="replyto" />

添加到 PFG 表单的日期/时间字段由多个 <select> 组成。输入而不是像上面那样的输入,我想这意味着没有简单的 obj.setEndDate()这个命令......虽然无法引用选择框,但我有点卡住了。

有谁知道是否可以创建事件内容类型 并指定开始和结束日期 在它上面,使用 Plone Form Gen?

编辑

Using this link我已经解决了最初的问题,但遇到了更多问题

我已经修改了我的脚本(使用上面的链接),如下所示:
target = context.viewjobs

form = request.form

from DateTime import DateTime
uid = str(DateTime().millis())

loc = form['location-of-event']

target.invokeFactory("Event", id=uid, title=form['topic'], event_url=loc)

obj = target[uid]

obj.setFormat('text/plain')
obj.setText(form['comments'])
obj.setDescription(form['replyto'])

obj.reindexObject()

(我使用 event_url 只是为了测试,因为我对 event_start 选项没有任何运气)。

它可以创建事件,但是当我去查看事件时,我得到:
 Module zope.tales.expressions, line 217, in __call__
Module Products.PageTemplates.Expressions, line 147, in _eval
Module zope.tales.expressions, line 124, in _eval
Module Products.PageTemplates.Expressions, line 74, in boboAwareZopeTraverse
Module OFS.Traversable, line 317, in restrictedTraverse
Module OFS.Traversable, line 285, in unrestrictedTraverse
__traceback_info__: ([], 'location')

属性错误:位置

我没有在脚本中的任何地方引用位置,当我这样做时,我得到了同样的错误。

任何想法将不胜感激

最佳答案

您可以通过执行以下操作来简化代码并避免 reindex 调用:

target = context.viewjobs

form = request.form

from DateTime import DateTime
uid = str(DateTime().millis())

target.invokeFactory(
"Event",
id=uid,
title=form['job-title'],
description=form['description-1'],
text=form['comments'],
location=form['location-of-event'],
startDate=form['start-date'],
endDate=form['end-date-due-by']
)

关于收集起止日期。如果您使用日期/时间小部件并查看生成的 HTML,您会注意到有一个隐藏的输入字段,其名称与小部件的短名称相匹配。该隐藏输入包含各种选择框所选择内容的完整文本表示,因此您希望通过使用文本字段来实现,而不必依赖用户使用特定格式。

如果您想知道如何找到要在 invokeFactory 调用中指定的各种字段的名称,请查找定义您尝试创建的内容类型的 python 文件。在事件对象的情况下,它是/Plone/buildout-cache/eggs/Products.ATContentTypes-2.1.8-py2.7.egg/Products/ATContentTypes/content/event.py

第 32 行以“ATEventSchema = ...”开头,从那里您将看到事件所有部分的字段名称。

关于plone - 使用 Plone Form Gen 创建事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15785926/

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