from Products.Five import BrowserView as BaseView from zope.interface import implements from zope.component import getUtility from Products.iva.interfaces import IIVAPlugin from interfaces import IWaramu, IWaramuTool from WaramuTool import WaramuTool def _getMyTool(ctx): return getattr(ctx, WaramuTool.id, None) class WaramuManagerAdapter(object): """ waramu manager adapter """ implements(IWaramu, IIVAPlugin) def __init__(self, context): self.context = context self.tool = _getMyTool(self.context) def _install(self): w = WaramuTool() if self.tool is None: self.context._setObject(w.id, w) sm = self.context.getSiteManager() sm.registerUtility(_getMyTool(self.context), IWaramuTool, name='waramutool') def _uninstall(self): sm = self.context.getSiteManager() sm.unregisterUtility(provided=IWaramuTool, name="waramutool") self.context._delObject(WaramuTool.id) def isInstalled(self): return self.tool def isVisible(self): return self.tool.isVisible()