敏捷内容类型DateTime问题&如何修改内容类型值

时间:2013-07-07 02:47:27

标签: dexterity contenttypes

首先:我正在使用敏捷内容类型2.0.7运行Plonce Plone 4.3(4305)实例

我的方法是编写一个Python脚本(通过ZMI添加),使用此处描述的invokeFactory(...)typestool.constructContent(..)方法创建我的敏捷内容类型:http://plone.org/documentation/kb/add-content-programmatically(我写过两篇执行相同任务但使用不同方法的脚本 - 用于学习目的)

一切正常,除非我尝试将DateTime对象添加到上述两种方法的构造函数中以创建我的内容类型。 Date字段仅仅更新日期和年份值。由于在python中导入库的限制,我使用此代码卡住(使用我目前的知识):

d = DateTime('12/12/2013')

我的脚本在完成后返回日期对象,如下所示:

2013/12/12 00:00:00 GMT+1

我写了另一个小脚本,它在构造后输出Date值,它给了我相同的结果(这似乎是正确的)。生成的内容类型的日期和年份字段已正确更新,但月份值保留在1月,并在查看时引发以下TypeError:

TypeError: int() argument must be a string or a number, not 'instancemethod'

我可以通过手动编辑月份值来解决这个问题,这不是我想要的。我想这是我的DateTime对象的一个​​小问题,但我现在已经没有想法了(整体文档似乎有点分散)。我在DateTime构造函数中尝试了各种日期格式,但没有运气。

我也不确定如何修改我的对象自定义字段值。 Plone似乎只提供setTitle()setDescription()方法。也许有人有一个很好的暗示。

先谢谢你们, 问候

2 个答案:

答案 0 :(得分:0)

不确定dateTime问题,但检查索引,索引和自定义索引以找出设置标题和说明。

设置实例的标题

@indexer(IFormName)
def titleIndexer(obj):
    return obj.valueFromForm
grok.global_adapter(titleIndexer, name="Title")

答案 1 :(得分:0)

AFAIK,问题是敏捷类型的DateTime字段需要一个datetime对象,而不是DateTime对象。

在invokeFactory中,您应该传递d​​atetime对象而不是DateTime对象

>>>date=datetime.datetime(2011,1,1)
>>>myobj=target.invokeFactory(type_name="content_type_name", id=id, date=date)

>>from DateTime import DateTime
>>DateTime().month() 
7
>>from datetime import datetime
>>datetime.now().month
7
>>datetime.now().month()
TypeError: 'int' object is not callable 

>>> myobj.date
datetime.datetime(2013, 7, 26, 0, 0) 
>>> myobj.date.month 
7
>>> myobj.date.month() 
TypeError: 'int' object is not callable