2012-04-23 65 views
2

我经常面临重写Viewlet问题,而且我经常不知道它为什么会起作用。如何在使用浏览器的Plone中调试Viewlet创建

我现在试图覆盖使用浏览器的collective.googleanalytics跟踪器viewlet,但不从plone.app.layout.viewlets.common.BaseViewlet继承。

为了实现这一目标,我创建了一个从c.googleanalytics继承的浏览器层,注册它并验证everthings进展顺利。

我还是不明白为什么使用c.googleanalytics的viewlet代替我的。

代码是在这里:https://github.com/toutpt/collective.linguaanalytics

我希望能够知道我在哪里可以添加PDB调试此。或者什么工具可以帮助。

编辑:

(Pdb) self.request.__provides__.__iro__ 
InterfaceClass plonetheme.sunburst.browser.interfaces.IThemeSpecific>, 
InterfaceClass plone.app.z3cform.interfaces.IPloneFormLayer>, 
InterfaceClass z3c.form.interfaces.IFormLayer>, 
InterfaceClass plone.app.discussion.interfaces.IDiscussionLayer>, 
InterfaceClass collective.linguaanalytics.interfaces.ILayer>, 
InterfaceClass collective.googleanalytics.interfaces.browserlayer.IAnalyticsLayer>, InterfaceClass plone.theme.interfaces.IDefaultPloneLayer>, 
InterfaceClass Products.CMFDefault.interfaces.ICMFDefaultSkin>, 
InterfaceClass zope.publisher.interfaces.browser.IDefaultBrowserLayer>, 
InterfaceClass zope.publisher.interfaces.browser.IBrowserRequest>, 
InterfaceClass zope.publisher.interfaces.http.IHTTPRequest>, 
InterfaceClass zope.publisher.interfaces.IRequest>, 
InterfaceClass zope.publisher.interfaces.IPublisherRequest>, 
InterfaceClass zope.publisher.interfaces.IPublicationRequest>, 
InterfaceClass zope.security.interfaces.IParticipation>, 
InterfaceClass zope.publisher.interfaces.IApplicationRequest>, 
InterfaceClass zope.interface.common.mapping.IEnumerableMapping>, 
InterfaceClass zope.interface.common.mapping.IReadMapping>, 
InterfaceClass zope.interface.common.mapping.IItemMapping>, 
InterfaceClass zope.publisher.interfaces.ISkinnable>, 
InterfaceClass zope.annotation.interfaces.IAttributeAnnotatable>, 
InterfaceClass zope.annotation.interfaces.IAnnotatable>, 
InterfaceClass zope.interface.Interface>) 

编辑: 看来他们都是围绕层的覆盖没有测试在plone.browserlayer的其他层。可能是一个错误?

+0

这很奇怪。你的代码看起来是正确的,因为你在你的ILayer中扩展IAnalyticsLayer。只有当您在GS配置文件中删除“分析”浏览器图层时,看起来有点腥。 – vangheem 2012-04-23 16:51:27

+1

将pdb粘贴到任何可以获取请求的位置,并让我们知道请求.__提供了__.__ iro__输出。 – 2012-04-24 02:18:43

+0

@vangheem删除分析图层是一个测试。我没有这个推。 – toutpt 2012-04-24 08:26:29

回答

3

哈哈,傻打错。 in viewlets/configure.zcml,viewlet是“AnalyticsTrackingViewlet”,来自collective.googleanalytics。

在你viewlets.py您覆盖这个类,但你被覆盖的类的真名是“AnalyticsViewlet”

加载ZCML的时候。因此,它会覆盖c.google.AnalyticsTrackingViewlet与... c.google .AnalyticsTrackingViewlet:D。

只需更改您的zcml即可使用AnalyticsViewlet并享受它。

0

这看起来很骇人。为什么不保留上游层?

您应该通过overrides.zcml进行覆盖。一旦工作/没有/图层限制,您可以将其绑定到干净的图层界面。

替代策略,不要覆盖上游viewlet,但通过GS隐藏它,并给你自己的viewlet一个不同的名称。再次,在一个干净的图层上。

+0

我知道关于overrides.zcml,但我认为这是奇怪的做一个插件需要overrides.zcml。我使用这个唯一的地方是当我需要卸载组件时(比如唱歌和跳舞)。所以这个解决方案是一个解决方法,只对项目有效。图层是改变现有viewlet行为的解决方案,我正在尝试在这里实现。 – toutpt 2012-04-24 08:33:22

相关问题