I have a custom portlet manager, and I'd like to blacklist (aka block) context (aka parent) portlets by default. I've found a couple of methods but they either require a specific location (so not sitewide) or will only work if I'm in a different package to where the portlet manager is defined (setuphanders.py is run before portlets.xml is imported and therefore the portlet manager doesn't exist yet), which is not a runner.
Wh开发者_如何学Pythonat I'd really like to do is use the genericSetup blacklist syntax in portlets.xml with a '*' for the location like this:
<blacklist
manager="custom.portletmanager"
location="*"
category="context"
status="block"
/>
But, alas, that doesn't seem to work. Any suggestions?
Perhaps you can override some permission on the portlet (possibly in overrides.zcml), requiring a non-existing permission?
Alternatively, there's a z3c.unconfigure
package that may be able to unregister the portlet entirely.
Better late than never, maybe: using this in your PortletManager's __init _ _ sets the default for inheriting to false, but you can still override it TTW. (This approach does not extend to the other two things, which have a ternary semantic of "block/show/inherit" already, so we can't distinguish a default value from a user-set value and __init _ _ is called every time.)
def __init__(self, context, request, view, manager):
ColumnPortletManagerRenderer.__init__(self, context, request, view, manager)
assignable = getMultiAdapter((self.context, self.manager,),
ILocalPortletAssignmentManager)
if assignable.getBlacklistStatus(CONTEXT_CATEGORY)==None:
# hack: for CONTEXT, it's a binary flag.
# Nevertheless, getBlacklistStatus returns ternary True/False/None.
# None should be the creation default.
assignable.setBlacklistStatus(CONTEXT_CATEGORY, True)
精彩评论