def test_remove_bundle_on_request_with_subrequest(self): req = self.layer['request'] # create a subrequest. subreq = req.clone() subreq['PARENT_REQUEST'] = req # remove the enabled 'foo' bundle remove_bundle_on_request(req, 'foo') scripts = ScriptsView(self.layer['portal'], subreq, None) # Send resource registry in development mode # Via a fake registry to allow accessing like this: # self.registry.records['plone.resources.development'].value scripts.registry = type( 'reg', (object, ), { 'records': { 'plone.resources.development': type('val', (object, ), {'value': True})() } })() self.assertTrue(scripts.development) scripts.update() results = scripts.scripts() self.assertEqual(filter(lambda it: 'foo' in it['src'], results), [])
def test_remove_bundle_on_request_with_subrequest(self): req = self.layer['request'] # create a subrequest. subreq = req.clone() subreq['PARENT_REQUEST'] = req # remove the enabled 'foo' bundle remove_bundle_on_request(req, 'foo') scripts = ScriptsView(self.layer['portal'], subreq, None) # Send resource registry in development mode # Via a fake registry to allow accessing like this: # self.registry.records['plone.resources.development'].value scripts.registry = type( 'reg', (object, ), {'records': { 'plone.resources.development': type( 'val', (object, ), {'value': True} )() }} )() self.assertTrue(scripts.development) scripts.update() results = scripts.scripts() self.assertEqual( filter(lambda it: 'foo' in it['src'], results), [] )
def filter_request(self): """ Manipulate the request to support the fallback theme: - Remove the 'normal' theme layer from the request to disable the diazo transform of that theme and fully fall back to the underlying configured theme, typically barceloneta. - Enable/disable resource bundles to restore the fallback theme. Typically involves removing the 'normal' theme bundle(s). Some control panels add a bundle to the request on rendering, and we make sure to play nice with that and extend rather than replace such request bundle settings. """ if self.request.get('ploneintranet.themeswitcher.marker'): return # manipulate the same request only once self.request.set('ploneintranet.themeswitcher.marker', True) if not self.isFallbackActive(): return # only on fallback, remove current theme browser layer(s) switcher = self.getSwitcherSettings() remove_layers = [ resolveDottedName(x) for x in switcher.browserlayer_filterlist ] active_layers = [ x for x in directlyProvidedBy(self.request) if x not in remove_layers ] directlyProvides(self.request, *active_layers) # CMFPlone/resource/browser/resource # supports enable/disable bundles directly on the request if switcher.fallback_enabled_bundles: for bundle in switcher.fallback_enabled_bundles: add_bundle_on_request(self.request, bundle) if switcher.fallback_disabled_bundles: for bundle in switcher.fallback_disabled_bundles: remove_bundle_on_request(self.request, bundle) else: log.warn("NO bundles disabled on fallback. That's weird.")
def filter_request(self): """ Manipulate the request to support the fallback theme: - Remove the 'normal' theme layer from the request to disable the diazo transform of that theme and fully fall back to the underlying configured theme, typically barceloneta. - Enable/disable resource bundles to restore the fallback theme. Typically involves removing the 'normal' theme bundle(s). Some control panels add a bundle to the request on rendering, and we make sure to play nice with that and extend rather than replace such request bundle settings. """ if self.request.get('ploneintranet.themeswitcher.marker'): return # manipulate the same request only once self.request.set('ploneintranet.themeswitcher.marker', True) if not self.isFallbackActive(): return # only on fallback, remove current theme browser layer(s) switcher = self.getSwitcherSettings() remove_layers = [resolveDottedName(x) for x in switcher.browserlayer_filterlist] active_layers = [x for x in directlyProvidedBy(self.request) if x not in remove_layers] directlyProvides(self.request, *active_layers) # CMFPlone/resource/browser/resource # supports enable/disable bundles directly on the request if switcher.fallback_enabled_bundles: for bundle in switcher.fallback_enabled_bundles: add_bundle_on_request(self.request, bundle) if switcher.fallback_disabled_bundles: for bundle in switcher.fallback_disabled_bundles: remove_bundle_on_request(self.request, bundle) else: log.warn("NO bundles disabled on fallback. That's weird.")