在 ajax 回调浏览器视图中更新文件系统上开发的自定义 portlet 我有以下代码来检索生成 ajax 请求的 portlet 的关联 portlet 分配:
def getPortletById(self, content, portletManager, key, name):
manager = getUtility(IPortletManager, name=portletManager, context=content)
retriever = getMultiAdapter((content, manager,), IPortletRetriever)
print "getPortletById: ",content, portletManager, key, name
print "iterating portlet assignements:"
for assignment in retriever.getPortlets():
print assignment["key"], assignment["name"]
if assignment["key"] == key and assignment["name"] == name:
return assignment["assignment"]
return None
def getPortletManager(self, column):
manager = getUtility(IPortletManager, name=column)
return manager
def render(self):
print "refreshment of moonphase portlet"
content = self.context.aq_inner
print self.context
name = self.request.form.get("portletName")
managername = self.request.form.get("portletManager")
key = self.request.form.get("portletKey")
print name, managername, key
portlet = self.getPortletById(content, managername, key, name)
manager = self.getPortletManager(managername)
managerRenderer = manager(content, self.request, self)
renderer = managerRenderer._dataToPortlet(portlet.data)
renderer.update()
return renderer.render()
只要将生成请求的 portlet 直接分配给内容或其父文件夹并显示出来,这种方法就可以很好地工作。但是,当我将文件夹的默认视图设置为分配给它的 portlet 的内容项时,迭代不会找到在页面上呈现的 portlet 作为默认文件夹视图的一部分。
<PloneSite at naturfreundeskreis>
moonphase-portlet plone.rightcolumn /naturfreundeskreis/naturfreundeskreis
getPortletById: <PloneSite at naturfreundeskreis> plone.rightcolumns /naturfreundeskreis/naturfreundeskreis moonphase-portlet
iterating portlet assignements
/naturfreundeskreis calendar
2013-03-19 13:48:31 ERROR Zope.SiteErrorLog 1363715311.150.739587723624 http://midgard.user.openhosting.com:8280/naturfreundeskreis/@@refreshMoonphase
Traceback (innermost last):
Module ZPublisher.Publish, line 126, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 46, in call_object
Module kuehnel.portlets.moonphase.moonphaseview, line 21, in __call__
Module kuehnel.portlets.moonphase.moonphaseview, line 59, in render
AttributeError: 'NoneType' object has no attribute 'data'
最初的 portlet 呈现过程确实以某种方式找到了 portlet,因为它被显示并生成了请求。但是我不能。我做错了什么?
使用浏览器视图传递 ajax 请求的内容片段是一种好习惯吗?
我将在一天结束时在https://github.com/tdkuehnel/kuehnel.portlets.moonphase更新整个 portlet 的 github 存储库,以反映当前的开发状态。
在 Centos 上构建 Plone 4.2.4