Plone定制大全

Plone定制大全
[align=center][size=5]系统讲述plone定制的各种方法。[/size][/align][font="]1. [/font]layer[font=宋体]概念
[/font]
[font="]1.1 [/font]theme layer[align=left][font=宋体]主题层在主题被启用时,生效。

[/font][/align][font="]1.1.1 [/font][font=宋体]定义接口[/font][align=left]Subclass aninterface from IDefaultPloneLayer[/align]
from plone.theme.interfaces import IDefaultPloneLayer
class IThemeSpecific(IDefaultPloneLayer):
"""Marker interface that defines a Zope 3 skin layer bound to a Skin
Selection in portal_skins.
If you need to register a viewlet only for the "YourSkin"
skin, this is the interface that must be used for the layer attribute
in YourSkin/browser/configure.zcml.
"""     
1.1.2 zcml 中注册主题层
<configure xmlns="http://namespaces.zope.org/zope"
           xmlns:browser="http://namespaces.zope.org/browser"              
           xmlns:five="http://namespaces.zope.org/five">           
    <interface
        interface=".interfaces.IThemeSpecific" 
        type="zope.publisher.interfaces.browser.IBrowserSkinType" 
        name="collective.diazotheme.bootstrap" />


[font=NimbusRomNo9L-Regu][size=10.0pt]1.1.3 在genericsetup配置文件中注册主题(皮肤) [/size][/font][font=NimbusRomNo9L-Regu][size=10.0pt]Declare your theme in profiles/default/skins.xml[/size][/font]
<?xml version="1.0"?>
<object name="portal_skins" allow_any="False" cookie_persistence="False"
   default_skin="collective.diazotheme.bootstrap">

 <object name="diazotheme_bootstrap_custom"
    meta_type="Filesystem Directory View"
    directory="collective.diazotheme.bootstrap:skins/diazotheme_bootstrap_custom"/>

 <skin-path name="collective.diazotheme.bootstrap" based-on="Sunburst Theme">
  <layer name="diazotheme_bootstrap_custom"
     insert-after="custom"/>
 </skin-path>

</object>

[font=&quot;]1.2 [/font]add-on layer[align=left][font=宋体]插件层在插件被安装时,生效。[/font][/align][align=left][font=宋体]插件层是这个包实现的:[/font]https://pypi.python.org/pypi/plone.browserlayer[/align][font=&quot;]1.2.1 [/font][font=宋体]创建接口[/font][align=left]createan an interface foryour layer in your.product.interfaces.py:[/align]
class IThemeSpecific(Interface):
    """Marker interface that defines a ZTK browser layer. We can reference
    this in the 'layer' attribute of ZCML <browser:* /> directives to ensure
    the relevant registration only takes effect when this theme is selected.
    
    The browser layer is installed via the browserlayer.xml GenericSetup
    import step.
    """

[font=&quot;]1.2.2 在genericsetup 配置文件中[/font][font=宋体]注册层[/font][align=left]profile/default/browserlayer.xmlfile[/align]
<layers>   
     
    <layer
        name="hjzgb.policy"
        interface="hjzgb.policy.browser.interfaces.IThemeSpecific"
        />

</layers>
[align=left]

无论是主题层还是插件层,都可以用于plone的可视化部件的定制,如view,viewlet,portlet等。
[/align][font=&quot;]2. [/font][font=宋体]主模板定制[/font][align=left][font=宋体]由于[/font]mian_template.pt[font=宋体]是[/font]skins[font=宋体]层里,所以必须定制一个更高级别的[/font]skin[font=宋体]层。[/font][/align][align=left]● Registering skins[/align][align=left]demo: Add new skin folder (skins.zcml + profiles/default/skins.xml)
skins.zcml实例:
... 
 <cmf:registerDirectory name="diazotheme_bootstrap_custom"/>
...
skins.xml实例:
<?xml version="1.0"?>
<object name="portal_skins" allow_any="False" cookie_persistence="False"
   default_skin="collective.diazotheme.bootstrap">

 <object name="diazotheme_bootstrap_custom"
    meta_type="Filesystem Directory View"
    directory="collective.diazotheme.bootstrap:skins/diazotheme_bootstrap_custom"/>

 <skin-path name="collective.diazotheme.bootstrap" based-on="Sunburst Theme">
  <layer name="diazotheme_bootstrap_custom"
     insert-after="custom"/>
 </skin-path>

</object>


[/align]
[font=&quot;]3. [/font][font=宋体]视图模板定制[/font][align=left][font=宋体]采用[/font]j3c.jbot[font=宋体]模块,实际上应用的主题层概念。[/font][/align][align=left][font=宋体]主题包的[/font] [size=12.0pt]manifest.cfg[/size][size=12.0pt]指定 新的模板文件夹。[/size][/align][align=left]https://pypi.python.org/pypi/plone.app.themingplugins/1.0b1[/align]

<includepackage=”z3c.jbot” file=”meta.zcml” />
<browser:jbot directory=”template-overrides”
layer=”.interfaces.IThemeSpecific”/>
[align=left]Templates can now go into theme/browser/template-overrides named by referencing the dotted pathto the file: [/align][align=left]例如:plone.app.layout.viewlets.footer.pt[/align][font=&quot;]4. [/font]viewlet[font=宋体]定制
[/font]
[font=&quot;]4.1 [/font][font=宋体]定制呈现逻辑(通过[/font]layer[font=宋体]来)[/font]


[font=&quot;]4.2 [/font][font=宋体]定制模板[/font][align=left][font=宋体]通过[/font]z3c.jbot[font=宋体]来实现。[/font][/align][font=&quot;]5. [/font][font=宋体]覆盖[/font]portlet[font=&quot;]
5.1 [/font]使用portletRenderer



5.2 隐藏portlet[align=left]Example portlets.xml:[/align]

6. 覆盖视图类
[font=&quot;]6.1 [/font][font=宋体]定义[/font]layer[font=宋体]层接口[/font][align=left][font=宋体]增加[/font]interfaces.py[/align]

[font=&quot;]6.2 [/font][font=宋体]注册插件层[/font]
[align=left]browserlayer.xml[/align]


[font=&quot;]6.3 [/font][font=宋体]改[/font]zcml[font=宋体]配置[/font][align=left]zcml [font=宋体]配置视图部分,增加[/font]layer [font=宋体]语句[/font][/align]

[font=&quot;]6.4 [/font][font=宋体]新的视图类[/font][align=left][font=宋体]在[/font]customregistration.py[/align][align=left][font=宋体]里面定义了[/font]CustomRegistrationForm[font=宋体]视图类[/font][/align]

[font=&quot;]7. [/font]monkeypatcher[align=left][font=宋体]覆盖某[/font]module[font=宋体]或某[/font]class[font=宋体]中指定的方法。参考:[/font]https://pypi.python.org/pypi/collective.monkeypatcher/1.0.1[/align]
<configure    xmlns="http://namespaces.zope.org/zope"   
 xmlns:monkey="http://namespaces.plone.org/monkey"   
 i18n_domain="collective.monkeypatcher">     
 <include package="collective.monkeypatcher" />    
 <monkey:patch        
   description="This works around issue <a target="_blank" href="http://some.tracker.tld/ticket/123">http://some.tracker.tld/ticket/123</a>"        
   class="Products.CMFPlone.CatalogTool.CatalogTool"       
   original="searchResults"        
   replacement=".catalog.patchedSearchResults"       
 /> 
</configure>

[font=&quot;]8. [/font][font=宋体]附注:
[/font]
[font=&quot;]8.1 [/font]z3c.jbot[align=left][font=宋体]可以覆盖[/font]viewlet,view.portlet,[font=宋体]以及[/font]skins[font=宋体]下的模板。[/font][/align][font=&quot;]8.2 [/font][font=宋体]更改后,需要重启的情况[/font][align=left]下面情况的更改需要重启Plone实例 [/align][align=left]* .zcml [/align][align=left]* .py [/align][align=left]* new z3c.jbotoverride
8.4 主题层和插件层适应场合
主题层一般用于皮肤包;插件曾一般用于策略包。
[/align]
设置