如何获取分配给自定义 portlet 管理器的日历 portlet 的 portlet-hash css 类?

发布于 2024-11-16 07:43:55 字数 1296 浏览 3 评论 0原文

我正在尝试修复分配给自定义 Portlet 管理器的日历 Portlet 的月份导航。该管理器是从特定的浏览器页面模板调用的:

<div id="calendar"
    tal:content="structure provider:my.custom.portletmanager" />

不幸的是,管理器没有为我渲染带有哈希值的包装器,因此我尝试手动将 kssattr-portlethash css 类附加到位于

标记之上,以便月份导航正常工作(refreshPortlet() 需要它)。我尝试了这个:

from plone.portlets.utils import hashPortletInfo
class SectionHomeView(BrowserView):
    """SectionHome browser view
    """
    implements(ISectionHomeView)

    def __init__(self, context, request):
        self.context = context
        self.request = request

    @property
    def getHash(self):
        info = dict(manager = 'my.custom.portletmanager',
                    category = 'context',
                    key = '/my-section',
                    name = 'mycalendar',
                   )
        return hashPortletInfo(info)

使用此代码我确实得到了哈希值,但日历导航仍然不起作用。 如何访问 portlet 信息(例如管理器、类别、键和名称)以便正确计算它?

我希望我具有 column.pt 所描述的行为 < em>plone.app.portlets.browser.templates 及其类 ColumnPortletManagerRenderer (portlets/manager.py) 但我不知道如何使我的自定义管理器提供那些(即:就像默认管理器一样)。

I'm trying to fix the month navigation of a calendar portlet assigned for a custom portlet manager. This manager is called from a specific browser page template with:

<div id="calendar"
    tal:content="structure provider:my.custom.portletmanager" />

Unfortunately the manager doesn't render a wrapper with the hash for me, so I'm trying to manually append a kssattr-portlethash css class to the above <div> tag in order to make the month navigation work (refreshPortlet() needs it). I tried this:

from plone.portlets.utils import hashPortletInfo
class SectionHomeView(BrowserView):
    """SectionHome browser view
    """
    implements(ISectionHomeView)

    def __init__(self, context, request):
        self.context = context
        self.request = request

    @property
    def getHash(self):
        info = dict(manager = 'my.custom.portletmanager',
                    category = 'context',
                    key = '/my-section',
                    name = 'mycalendar',
                   )
        return hashPortletInfo(info)

Using this code I do get a hash, but calendar navigation still doesn't work. How can I access the portlet info such as manager, category, key and name in order to compute it right?

I wish I had the behaviour described by column.pt from plone.app.portlets.browser.templates and its class ColumnPortletManagerRenderer (portlets/manager.py) but I don't know how to make my custom manager provide those (ie: like the default managers do).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挥剑断情 2024-11-23 07:43:55

您需要确保安装了知道渲染散列的 PortletManagerRenderer 和 EditPortletManagerRenderer,例如:

class MyCustomPortletManagerRenderer(ColumnPortletManagerRenderer) :
    """ This custom version of ColumnPortletManagerRenderer points to a new 
    template so that HTML can be customised. 
    """
    adapts(Interface, IThemeSpecific, IBrowserView, IMyCustomPortletManager)
    template = ViewPageTemplateFile('column.pt')

    def can_manage_portlets(self):
        context = self._context()
        if not ILocalPortletAssignable.providedBy(context):
            return False
        mtool = getToolByName(context, 'portal_membership')
        return mtool.checkPermission("Portlets: Manage portlets", context)

class MyCustomEditPortletManagerRenderer(ContextualEditPortletManagerRenderer):
    """To allow edit support of the above.
    """
    adapts(Interface, IThemeSpecific, IManageContextualPortletsView, IMyCustomPortletManager)
    template = ViewPageTemplateFile('edit-column.pt')

其中 column.pt 如下所示:

<tal:block repeat="portlet options/portlets">
<div tal:attributes="class string:portletWrapper kssattr-portlethash-${portlet/hash};"
     tal:content="structure python:view.safe_render(portlet['renderer'])" />
</tal:block>

You need to make sure you have a PortletManagerRenderer and an EditPortletManagerRenderer installed that know to render hashes, such as:

class MyCustomPortletManagerRenderer(ColumnPortletManagerRenderer) :
    """ This custom version of ColumnPortletManagerRenderer points to a new 
    template so that HTML can be customised. 
    """
    adapts(Interface, IThemeSpecific, IBrowserView, IMyCustomPortletManager)
    template = ViewPageTemplateFile('column.pt')

    def can_manage_portlets(self):
        context = self._context()
        if not ILocalPortletAssignable.providedBy(context):
            return False
        mtool = getToolByName(context, 'portal_membership')
        return mtool.checkPermission("Portlets: Manage portlets", context)

class MyCustomEditPortletManagerRenderer(ContextualEditPortletManagerRenderer):
    """To allow edit support of the above.
    """
    adapts(Interface, IThemeSpecific, IManageContextualPortletsView, IMyCustomPortletManager)
    template = ViewPageTemplateFile('edit-column.pt')

Where column.pt looks like:

<tal:block repeat="portlet options/portlets">
<div tal:attributes="class string:portletWrapper kssattr-portlethash-${portlet/hash};"
     tal:content="structure python:view.safe_render(portlet['renderer'])" />
</tal:block>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文