使用Plone Form Gen创建事件

Dan*_*Dan 6 plone ploneformgen

我正在尝试使用Plone Form Gen创建一个事件内容类型.我一直在使用本教程来执行此操作.

使用Add New...菜单创建事件内容类型时,您将获得两个要填写的字段,即事件的开始日期和结束日期,我希望我的表单从这些字段中提取信息并将其应用于事件内容类型我是用来创建它.

我理解的问题用以下例子描述:

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

obj.setDescription(form['replyto'])
Run Code Online (Sandbox Code Playgroud)

我可以看到它从以下内容获取事件内容类型描述的内容:

<input id="replyto" class="" type="text" size="30" name="replyto" />
Run Code Online (Sandbox Code Playgroud)

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

有没有人知道是否可以创建一个事件内容类型使用Plone Form Gen 指定它的开始和结束日期

编辑

使用此链接我已经解决了原始问题,但我遇到了更多问题

我已经调整了我的脚本(使用上面的链接),如下所示:

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()
Run Code Online (Sandbox Code Playgroud)

(我使用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')
Run Code Online (Sandbox Code Playgroud)

AttributeError:location

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

任何想法将不胜感激

Pau*_*ulR 5

您可以通过执行以下操作来简化代码并避免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']
    )
Run Code Online (Sandbox Code Playgroud)

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

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

第32行开始"ATEventSchema = ...",然后您将看到事件所有部分的字段名称.