ReferenceField 导致 AttributeError: 'function'对象没有属性“__of__”在自定义内容类型中
我创建了一个具有 ReferenceField 的自定义内容类型。当我将 allowed_types 设置为默认内容类型(例如文档或文件夹)时,我在保存或重新索引时不会遇到任何问题。但是,当我将 allowed_types 设置为另一个自定义内容类型时,我收到一个非常奇怪的错误。看来我可以在 ReferenceField 中设置 UID,并且 base_view 不会中断,但我无法保存或重新索引该对象。
使用: 克隆人4.0.1 佐普 2.12.11 Python 2.6.5(r265:79063,2010 年 11 月 21 日,11:58:21)[GCC 4.2.1(Apple Inc. build 5664)]
有什么想法吗?
atapi.ReferenceField(
'issue_source',
storage=atapi.AnnotationStorage(),
widget=atapi.ReferenceWidget(
label=_(u"Issue Source"),
description=_(u"Please select the source document to which this issue corresponds."),
),
required=True,
relationship='issue_issue_source',
allowed_types=('Source Document'), # specify portal type names here ('Example Type',)
multiValued=False, #One to One relationship
),
在 ipzope 中:
>>> issue
<Issue at /Plone/Members/test_user2/test-issue>
>>> issue.isReferenceable
1
>>> source_document
<SourceDocument at /Plone/test-folder/test-doc>
>>> issue.setIssue_source(source_document.UID())
>>> issue.getIssue_source()
<SourceDocument at /Plone/test-folder/test-doc>
>>> source_document
<SourceDocument at /Plone/test-folder/test-doc>
>>> issue.reindexObject()
> /Applications/Plone/plone-site/eggs/Products.CMFDynamicViewFTI-4.0-py2.6.egg/Products/CMFDynamicViewFTI/browserdefault.py(77)__call__()
76 context = aq_inner(self)
---> 77 template = template.__of__(context)
78 return template(context, context.REQUEST)
ipdb> quit
------------------------------------------------------------
Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
File "/Applications/Plone/plone-site/eggs/Products.Archetypes-1.6.3-py2.6.egg/Products/Archetypes/CatalogMultiplex.py", line 123, in reindexObject
c.catalog_object(self, url, idxs=lst)
File "/Applications/Plone/plone-site/eggs/Plone-4.0.1-py2.6.egg/Products/CMFPlone/CatalogTool.py", line 287, in catalog_object
update_metadata, pghandler=pghandler)
File "/Applications/Plone/plone-site/eggs/Products.PDBDebugMode-1.3.1-py2.6.egg/Products/PDBDebugMode/zcatalog.py", line 20, in catalog_object
update_metadata=update_metadata, pghandler=pghandler)
File "/Applications/Plone/plone-site/eggs/Zope2-2.12.11-py2.6-macosx-10.4-x86_64.egg/Products/ZCatalog/ZCatalog.py", line 529, in catalog_object
update_metadata=update_metadata)
File "/Applications/Plone/plone-site/eggs/Zope2-2.12.11-py2.6-macosx-10.4-x86_64.egg/Products/ZCatalog/Catalog.py", line 348, in catalogObject
self.updateMetadata(object, uid)
File "/Applications/Plone/plone-site/eggs/Zope2-2.12.11-py2.6-macosx-10.4-x86_64.egg/Products/ZCatalog/Catalog.py", line 278, in updateMetadata
newDataRecord = self.recordify(object)
File "/Applications/Plone/plone-site/eggs/Zope2-2.12.11-py2.6-macosx-10.4-x86_64.egg/Products/ZCatalog/Catalog.py", line 417, in recordify
if(attr is not MV and safe_callable(attr)): attr=attr()
File "/Applications/Plone/plone-site/eggs/Products.CMFDynamicViewFTI-4.0-py2.6.egg/Products/CMFDynamicViewFTI/browserdefault.py", line 77, in __call__
template = template.__of__(context)
AttributeError: 'function' object has no attribute '__of__'
当我通过网络单击“保存”时,我收到略有不同的错误消息:
2011-08-09 15:19:16 ERROR Zope.SiteErrorLog 1312895956.510.252592718824 http://127.0.0.1:8080/Plone/Members/test_user2/test-doc/atct_edit
Traceback (innermost last):
Module ZPublisher.Publish, line 127, in publish
Module ZPublisher.mapply, line 77, in mapply
Module Products.PDBDebugMode.runcall, line 70, in pdb_runcall
Module ZPublisher.Publish, line 47, in call_object
Module Products.CMFFormController.FSControllerPageTemplate, line 91, in __call__
Module Products.CMFFormController.BaseControllerPageTemplate, line 28, in _call
Module Products.CMFFormController.ControllerBase, line 231, in getNext
Module Products.CMFFormController.Actions.TraverseTo, line 38, in __call__
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 47, in call_object
Module Products.CMFFormController.FSControllerPythonScript, line 107, in __call__
Module Products.CMFFormController.ControllerBase, line 231, in getNext
Module Products.CMFFormController.Actions.TraverseTo, line 38, in __call__
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 47, in call_object
Module Products.CMFFormController.FSControllerPythonScript, line 105, in __call__
Module Products.CMFFormController.Script, line 145, in __call__
Module Products.CMFCore.FSPythonScript, line 130, in __call__
Module Shared.DC.Scripts.Bindings, line 324, in __call__
Module Shared.DC.Scripts.Bindings, line 361, in _bindAndExec
Module Products.PythonScripts.PythonScript, line 344, in _exec
Module script, line 1, in content_edit
- <FSControllerPythonScript at /Plone/content_edit used for /Plone/Members/test_user2/test-doc>
- Line 1
Module Products.CMFCore.FSPythonScript, line 130, in __call__
Module Shared.DC.Scripts.Bindings, line 324, in __call__
Module Shared.DC.Scripts.Bindings, line 361, in _bindAndExec
Module Products.PythonScripts.PythonScript, line 344, in _exec
Module script, line 13, in content_edit_impl
- <FSPythonScript at /Plone/content_edit_impl used for /Plone/Members/test_user2/test-doc>
- Line 13
Module Products.Archetypes.BaseObject, line 658, in processForm
Module Products.Archetypes.BaseObject, line 650, in _processForm
- __traceback_info__: (<Issue at /Plone/Members/test_user2/test-doc>, <Field nextPreviousEnabled(boolean:rw)>, <bound method Issue.setNextPreviousEnabled of <Issue at /Plone/Members/test_user2/test-doc>>)
Module Products.Archetypes.CatalogMultiplex, line 123, in reindexObject
Module Products.CMFPlone.CatalogTool, line 287, in catalog_object
Module Products.PDBDebugMode.zcatalog, line 20, in catalog_object
Module Products.ZCatalog.ZCatalog, line 529, in catalog_object
Module Products.ZCatalog.Catalog, line 348, in catalogObject
Module Products.ZCatalog.Catalog, line 278, in updateMetadata
Module Products.ZCatalog.Catalog, line 417, in recordify
Module Products.CMFDynamicViewFTI.browserdefault, line 77, in __call__
AttributeError: 'function' object has no attribute '__of__'
> /Applications/Plone/plone-site/eggs/Products.CMFDynamicViewFTI-4.0-py2.6.egg/Products/CMFDynamicViewFTI/browserdefault.py(77)__call__()
76 context = aq_inner(self)
---> 77 template = template.__of__(context)
78 return template(context, context.REQUEST)
I have created a custom content type that has a ReferenceField. When I set allowed_types to a default content type, such as Document or Folder, I do not get any problems upon saving or reindexing. However, when I set allowed_types to another custom content type, I get a very strange error. It appears I can set the UID in the ReferenceField fine and base_view does not break, but I cannot save or reindex the object.
Using:
Plone 4.0.1
Zope 2.12.11
Python 2.6.5 (r265:79063, Nov 21 2010, 11:58:21) [GCC 4.2.1 (Apple Inc. build 5664)]
Any ideas?
atapi.ReferenceField(
'issue_source',
storage=atapi.AnnotationStorage(),
widget=atapi.ReferenceWidget(
label=_(u"Issue Source"),
description=_(u"Please select the source document to which this issue corresponds."),
),
required=True,
relationship='issue_issue_source',
allowed_types=('Source Document'), # specify portal type names here ('Example Type',)
multiValued=False, #One to One relationship
),
In ipzope:
>>> issue
<Issue at /Plone/Members/test_user2/test-issue>
>>> issue.isReferenceable
1
>>> source_document
<SourceDocument at /Plone/test-folder/test-doc>
>>> issue.setIssue_source(source_document.UID())
>>> issue.getIssue_source()
<SourceDocument at /Plone/test-folder/test-doc>
>>> source_document
<SourceDocument at /Plone/test-folder/test-doc>
>>> issue.reindexObject()
> /Applications/Plone/plone-site/eggs/Products.CMFDynamicViewFTI-4.0-py2.6.egg/Products/CMFDynamicViewFTI/browserdefault.py(77)__call__()
76 context = aq_inner(self)
---> 77 template = template.__of__(context)
78 return template(context, context.REQUEST)
ipdb> quit
------------------------------------------------------------
Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
File "/Applications/Plone/plone-site/eggs/Products.Archetypes-1.6.3-py2.6.egg/Products/Archetypes/CatalogMultiplex.py", line 123, in reindexObject
c.catalog_object(self, url, idxs=lst)
File "/Applications/Plone/plone-site/eggs/Plone-4.0.1-py2.6.egg/Products/CMFPlone/CatalogTool.py", line 287, in catalog_object
update_metadata, pghandler=pghandler)
File "/Applications/Plone/plone-site/eggs/Products.PDBDebugMode-1.3.1-py2.6.egg/Products/PDBDebugMode/zcatalog.py", line 20, in catalog_object
update_metadata=update_metadata, pghandler=pghandler)
File "/Applications/Plone/plone-site/eggs/Zope2-2.12.11-py2.6-macosx-10.4-x86_64.egg/Products/ZCatalog/ZCatalog.py", line 529, in catalog_object
update_metadata=update_metadata)
File "/Applications/Plone/plone-site/eggs/Zope2-2.12.11-py2.6-macosx-10.4-x86_64.egg/Products/ZCatalog/Catalog.py", line 348, in catalogObject
self.updateMetadata(object, uid)
File "/Applications/Plone/plone-site/eggs/Zope2-2.12.11-py2.6-macosx-10.4-x86_64.egg/Products/ZCatalog/Catalog.py", line 278, in updateMetadata
newDataRecord = self.recordify(object)
File "/Applications/Plone/plone-site/eggs/Zope2-2.12.11-py2.6-macosx-10.4-x86_64.egg/Products/ZCatalog/Catalog.py", line 417, in recordify
if(attr is not MV and safe_callable(attr)): attr=attr()
File "/Applications/Plone/plone-site/eggs/Products.CMFDynamicViewFTI-4.0-py2.6.egg/Products/CMFDynamicViewFTI/browserdefault.py", line 77, in __call__
template = template.__of__(context)
AttributeError: 'function' object has no attribute '__of__'
When I click save through the web I get a slightly different error message:
2011-08-09 15:19:16 ERROR Zope.SiteErrorLog 1312895956.510.252592718824 http://127.0.0.1:8080/Plone/Members/test_user2/test-doc/atct_edit
Traceback (innermost last):
Module ZPublisher.Publish, line 127, in publish
Module ZPublisher.mapply, line 77, in mapply
Module Products.PDBDebugMode.runcall, line 70, in pdb_runcall
Module ZPublisher.Publish, line 47, in call_object
Module Products.CMFFormController.FSControllerPageTemplate, line 91, in __call__
Module Products.CMFFormController.BaseControllerPageTemplate, line 28, in _call
Module Products.CMFFormController.ControllerBase, line 231, in getNext
Module Products.CMFFormController.Actions.TraverseTo, line 38, in __call__
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 47, in call_object
Module Products.CMFFormController.FSControllerPythonScript, line 107, in __call__
Module Products.CMFFormController.ControllerBase, line 231, in getNext
Module Products.CMFFormController.Actions.TraverseTo, line 38, in __call__
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 47, in call_object
Module Products.CMFFormController.FSControllerPythonScript, line 105, in __call__
Module Products.CMFFormController.Script, line 145, in __call__
Module Products.CMFCore.FSPythonScript, line 130, in __call__
Module Shared.DC.Scripts.Bindings, line 324, in __call__
Module Shared.DC.Scripts.Bindings, line 361, in _bindAndExec
Module Products.PythonScripts.PythonScript, line 344, in _exec
Module script, line 1, in content_edit
- <FSControllerPythonScript at /Plone/content_edit used for /Plone/Members/test_user2/test-doc>
- Line 1
Module Products.CMFCore.FSPythonScript, line 130, in __call__
Module Shared.DC.Scripts.Bindings, line 324, in __call__
Module Shared.DC.Scripts.Bindings, line 361, in _bindAndExec
Module Products.PythonScripts.PythonScript, line 344, in _exec
Module script, line 13, in content_edit_impl
- <FSPythonScript at /Plone/content_edit_impl used for /Plone/Members/test_user2/test-doc>
- Line 13
Module Products.Archetypes.BaseObject, line 658, in processForm
Module Products.Archetypes.BaseObject, line 650, in _processForm
- __traceback_info__: (<Issue at /Plone/Members/test_user2/test-doc>, <Field nextPreviousEnabled(boolean:rw)>, <bound method Issue.setNextPreviousEnabled of <Issue at /Plone/Members/test_user2/test-doc>>)
Module Products.Archetypes.CatalogMultiplex, line 123, in reindexObject
Module Products.CMFPlone.CatalogTool, line 287, in catalog_object
Module Products.PDBDebugMode.zcatalog, line 20, in catalog_object
Module Products.ZCatalog.ZCatalog, line 529, in catalog_object
Module Products.ZCatalog.Catalog, line 348, in catalogObject
Module Products.ZCatalog.Catalog, line 278, in updateMetadata
Module Products.ZCatalog.Catalog, line 417, in recordify
Module Products.CMFDynamicViewFTI.browserdefault, line 77, in __call__
AttributeError: 'function' object has no attribute '__of__'
> /Applications/Plone/plone-site/eggs/Products.CMFDynamicViewFTI-4.0-py2.6.egg/Products/CMFDynamicViewFTI/browserdefault.py(77)__call__()
76 context = aq_inner(self)
---> 77 template = template.__of__(context)
78 return template(context, context.REQUEST)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这看起来确实很奇怪,一些提示:
将元组传递到 allowed_types 而不是字符串:
确保您没有 id 与目录索引 id 匹配的内容项。另请确保您没有对
getIssue_source
建立索引,但如果需要,请使用getRawIssue_source
。引用字段返回真实内容对象,因此使用普通访问器会将真实内容对象存储在目录中。这会在以后带来很多惊喜和问题。原始访问器返回一个 uuid 或 uuid 列表,您可以在目录查询中使用它们,例如:This looks strange indeed, some tips:
Pass a tuple into allowed_types instead of string:
Make sure you don't have a content item with an id that matches a catalog index id. Also make sure you don't index
getIssue_source
but if you need to, usegetRawIssue_source
. Reference fields return real content objects, so using the normal accessor would store the real content objects in the catalog. That will lead to a lot of surprises and problems later on. The raw accessor returns a uuid or a list of uuids, which you can use in a catalog query like: