Skip to content. | Skip to navigation

Personal tools

Navigation

You are here: Home / Tips / Portlet Management

Portlet Management

資訊方框是 Portlet 的翻譯名稱,它們通常位於網頁右側或右側的畫面區塊,用來顯示摘要資訊或執行特定功能,例如最新消息、行事曆、全文搜尋等。

架構更新

每個目錄或頁面,都可以設定資訊方框,在網址後面加上 /@@manage-portlets 就能進入設定介面。

調整資訊方框設定值

調整網站根目錄的 portlet 設定值,取消右邊方框的顯示。

系統預設是在網頁右邊顯示 news portlet 和 event portlet,目前移到左邊。

http://opensourcehacker.com/2011/03/10/how%C2%A0to-render-a-portlet-in-plone/

Add Image to News Portlet

<img src="" alt=""
 tal:define="item_object obj/getObject;"
 tal:condition="exists:item_object/image_thumb"
 tal:replace="strcture python: path('nocall:item_object/tag')(scale='thumb', css_class='tileImage')" />

Navigation

navtree_properties: Hide Contact Types from the Navigation

模組開發

資訊方框的元件通常包括 Schema Interface、Assignment Class、Add Form、Edit Form、Portlet Renderer。

>>> import zope.component
>>> site = app.site  # or your plone site
>>> manager = zope.component.queryUtility(IPortletManager, name='plone.leftcolumn', context=site)
>>> list(manager.keys())
[u'content_type', u'group', u'user']
>>> list(manager['content_type'].keys())
[u'ExampleContent', u'ExampleDocument', ...]
>>> del manager['content_type'][u'ExampleContent']
>>> import transaction
>>> transaction.commit()

If you have specific portlets you need to remove, you have to reinstall the product that contains your broken portlets, as you will get an error if you try to do this:

>>> list(manager['content_type'][u'ExampleDocument'].items()
[(u'example_portlet', ), ...
>>> del manager['content_type'][u'ExampleContent'][u'example_portlet']
Traceback (most recent call last):
...
AttributeError: __parent__

Portlet 是 plone.portlets.interfaces.IPortletType 註冊為 local utility 形式,下列範例可以檢查註冊狀況

p = app.unrestrictedTraverse("path to your site object")
from plone.portlets.interfaces import IPortletType
from zope.app.component.hooks import setSite
setSite(p)
cr = p.getSiteManager()
portlet_types = [r.name for r in cr.registeredUtilityes() if r.provided==IPortletType]
print portlet_types

新增 CSS 欄位範例: collective.portlet.embed

Ordering

調整顯示順序的方法 Programmatically Replacing

Extend Navigation Portlet ftw.treeview (2014-03-05 tried, with no screen appearing)

Navigation Portlet 排序調整

在 configure.zcml 裡,除了註冊 Extension Profile 之外,還有一個 Retriever 註冊動作:

<adapter factory=".portlets.PortletPageRetriever" />

Portlet Refresh Passing the URL of the Context

Programmatically Remove Broken Portlets

Manage Portlet Permission

Expand / Collapse for Navigation Portlet

Group Fields into Fieldset

Remember to Uninstall

plone.app.portlets 2.4.5 版本在執行 export 時,並不會完整處理子目錄的設定值。

Browser View to Remove Portlets

Local Portlet Checkbox: collective.portletmetadata for ContentWellPortlets

quintagroup.slidertemplates: Responsive Views for NGCollection Portlet with Carousel Shelf Tabs

collective.portlet.carousel: for collective.panels

unipdgest.portlet.navigation: accordion

qi.portlet.TagClouds

collective.facebook.portlets collective.portlet.fullview

portlets/analyticsportlet.pt

<dd class="portletItem odd">
            <div tal:attributes="id view/getContainerId;"
                class="analytics-async-container"></div>
            <script type="text/javascript" tal:content="view/getJavascript"></script>
</dd>

portlets/analyticsportlet.py

    def getJavascript(self):
        """
        Returns a list of AnalyticsReportResults objects for the selected reports.
        """

        return self.async_loader.getJavascript(self.data.reports, self.data.profile)

Conditional Display

例子之一,在點選 Share 頁籤 (執行 @@sharing) 不想顯示 Portlet 的話,至少有兩種方法,一是 CSS display: none 方式,二是修改 Main Template 的 sl 和 sr 條件。

tal:define="sl python:plone_view.have_portlets('plone.leftcolumn', view);
            sr python:plone_view.have_portlets('plone.rightcolumn', view);"

Plone 5 Compatibility

使用 z3c.form 取代 formlib,不改程式碼的話,可能會遇到 NotImplementedError: The class deriving from AutoExtensibleForm must have a 'schema' property 錯誤,由於 Plone 5 的 AddForm EditForm 需要 schema 屬性值,在 Plone 4 是使用 form_fields,最簡單的方式是增加 schema 設定值,內容就是 Interface:

 class AddForm(base.AddForm):
+    schema = IExamplePortlet
     form_fields = form.Fields(IExamplePortlet)

     def create(self, data):
         return Assignment(**data)

Display Float Image Portlet Relative to Page Bottom

plone.app.portlets now contains the fix that allows you to delete broken portlet assignment

collective.portlet.tal

Wienlets: alternative

plone.directives.form vs plone.portlets.interfaces.IPortletDataProvider