2012-04-23 62 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

相關問題