def testExpressionType(self): xmlconfig(StringIO(template % ( """ <tales:expressiontype name="test" handler="zope.app.pagetemplate.tests.test_directives.Handler" /> """ ))) self.assert_("test" in Engine.getTypes()) self.assert_(Handler is Engine.getTypes()['test'])
def setUp(test): setup.placefulSetUp(True) setup.setUpTraversal() setUpControlPanel() Engine.registerType(u'formatter', FormatterExpression) TrustedEngine.registerType(u'formatter', FormatterExpression) provideAdapter(dformatter.DateFormatterFactory, name='date') provideAdapter(dtformatter.DatetimeFormatterFactory, name='dateTime') provideAdapter( fancydatetime.FancyDatetimeFormatterFactory, name='fancyDatetime') provideAdapter( humandatetime.HumanDatetimeFormatterFactory, name='humanDatetime') provideAdapter(timeformatter.TimeFormatterFactory, name='time')
def subMenuItem( self, _context, submenu, title, description=u"", action=u"", icon=None, filter=None, permission=None, extra=None, order=0, ): if filter is not None: filter = Engine.compile(filter) if order == 0: order = _order_counter.get(self.for_, 1) _order_counter[self.for_] = order + 1 factory = MenuItemFactory( BrowserSubMenuItem, title=title, description=description, icon=icon, action=action, filter=filter, permission=permission, extra=extra, order=order, _for=self.for_, submenuId=submenu, ) adapter(_context, (factory,), self.menuItemType, (self.for_, self.layer), name=title)
def subMenuItem(self, _context, submenu, title, description=u'', action=u'', icon=None, filter=None, permission=None, extra=None, order=0, item_class=None): if filter is not None: filter = Engine.compile(filter) if permission is None: permission = self.permission if order == 0: order = _order_counter.get(self.for_, 1) _order_counter[self.for_] = order + 1 if item_class is None: item_class = self.subMenuItemClass if not IBrowserSubMenuItem.implementedBy(item_class): raise ValueError("Item class (%s) must implement IBrowserSubMenuItem" % item_class) factory = MenuItemFactory( item_class, title=title, description=description, icon=icon, action=action, filter=filter, permission=permission, extra=extra, order=order, _for=self.for_, submenuId=submenu) adapter(_context, (factory,), self.menuItemType, (self.for_, self.layer), name=title)
def available(self): """See zope.app.publisher.interfaces.browser.IBrowserMenuItem""" # Make sure we have the permission needed to access the menu's action if self.permission is not None: # If we have an explicit permission, check that we # can access it. if not checkPermission(self.permission, self.context): return False elif self.action != u'': # Otherwise, test access by attempting access path = self.action l = self.action.find('?') if l >= 0: path = self.action[:l] traverser = PublicationTraverser() try: view = traverser.traverseRelativeURL(self.request, self.context, path) except (Unauthorized, Forbidden, LookupError): return False else: # we're assuming that view pages are callable # this is a pretty sound assumption if not canAccess(view, '__call__'): return False # Make sure that we really want to see this menu item if self.filter is not None: try: include = self.filter( Engine.getContext( context=self.context, nothing=None, request=self.request, modules=sys.modules, )) except Unauthorized: return False else: if not include: return False return True
def available(self): """See zope.app.publisher.interfaces.browser.IBrowserMenuItem""" # Make sure we have the permission needed to access the menu's action if self.permission is not None: # If we have an explicit permission, check that we # can access it. if not checkPermission(self.permission, self.context): return False elif self.action != u'': # Otherwise, test access by attempting access path = self.action l = self.action.find('?') if l >= 0: path = self.action[:l] traverser = PublicationTraverser() try: view = traverser.traverseRelativeURL( self.request, self.context, path) except (Unauthorized, Forbidden, LookupError): return False else: # we're assuming that view pages are callable # this is a pretty sound assumption if not canAccess(view, '__call__'): return False # Make sure that we really want to see this menu item if self.filter is not None: try: include = self.filter(Engine.getContext( context = self.context, nothing = None, request = self.request, modules = sys.modules, )) except Unauthorized: return False else: if not include: return False return True
def clear(): Engine.__init__() _Engine(Engine) TrustedEngine.__init__() _TrustedEngine(TrustedEngine)
def registerType(name, handler): Engine.registerType(name, handler) TrustedEngine.registerType(name, handler)