Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the portlet-hash css class for a Calendar portlet assigned for a custom portlet manager?

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).

like image 987
Davi Lima Avatar asked Oct 11 '22 17:10

Davi Lima


1 Answers

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>
like image 64
MatthewWilkes Avatar answered Oct 14 '22 02:10

MatthewWilkes