如何更改portlet顺序(首先放置父portlet)

Adr*_*ner 2 plone

我如何重新排序portlet,以便继承的父portlet位于当前项的portlet之前?

hve*_*rde 5

Mathias解决方案似乎更容易; 无论如何,如果您不想安装第三方产品,我想留下这些文件.

您可以通过编写适配器来更改portlet的排序方式.例如,下面的一个对提供IATImage接口(图像)的任何对象重新排序portlet,因此首先呈现内容类型portel,然后是组1,最后是上下文:

from plone.portlets.interfaces import IPortletManager
from plone.portlets.interfaces import IPortletRetriever
from plone.portlets.retriever import PortletRetriever as BaseRetriever
from Products.ATContentTypes.interfaces import IATImage
from zope.component import adapts
from zope.interface import implements


class PortletRetriever(BaseRetriever):
    implements(IPortletRetriever)
    adapts(IATImage, IPortletManager)

    def getPortlets(self):
        assignments = super(PortletRetriever, self).getPortlets()
        context = [p for p in assignments if p['category'] == 'context']
        group = [p for p in assignments if p['category'] == 'group']
        content_type = [p for p in assignments if p['category'] == 'content_type']
        new_assignments = content_type + group + context
        return new_assignments
Run Code Online (Sandbox Code Playgroud)

不要忘记在ZCML文件中使用以下内容注册适配器:

<configure xmlns="http://namespaces.zope.org/zope">
  ...
  <adapter factory=".adapters.PortletRetriever" />
  ...
</configure>
Run Code Online (Sandbox Code Playgroud)