def theming_policy(request=None): """Primary policy accessor, uses pluggable ZCA lookup. Resolves into a IThemingPolicy adapter.""" if not request: request = getRequest() if not request: request = NoRequest() # the adapter knows how to handle this return IThemingPolicy(request)
def cached(*args, **kwargs): if not CACHE or getConfiguration().debug_mode: return func(*args, **kwargs) request = getRequest() policy = IThemingPolicy(request) cache_ = policy.getCache() if not hasattr(cache_, 'collective.themesitesetup'): setattr(cache_, 'collective.themesitesetup', {}) cache_ = getattr(cache_, 'collective.themesitesetup') if callable(key): key_ = key(*args) else: key_ = key if key_ not in cache_: cache_[key_] = func(*args, **kwargs) return cache_[key_]
def cached(*args, **kwargs): if not CACHE or getConfiguration().debug_mode: return func(*args, **kwargs) request = getRequest() policy = IThemingPolicy(request) cache_ = policy.getCache() if not hasattr(cache_, 'collective.themefragments'): setattr(cache_, 'collective.themefragments', {}) cache_ = getattr(cache_, 'collective.themefragments') if callable(key): key_ = key(*args) else: key_ = key if key_ not in cache_: cache_[key_] = func(*args, **kwargs) return cache_[key_]
def applyTheme(theme): """Apply an ITheme """ # on write, force using default policy policy = IThemingPolicy(NoRequest()) settings = policy.getSettings() plugins = None themeDirectory = None pluginSettings = None currentTheme = policy.getCurrentTheme() if currentTheme is not None: themeDirectory = queryResourceDirectory(THEME_RESOURCE_NAME, currentTheme) if themeDirectory is not None: plugins = getPlugins() pluginSettings = getPluginSettings(themeDirectory, plugins) if theme is None: settings.currentTheme = None settings.rules = None settings.absolutePrefix = None settings.parameterExpressions = {} settings.doctype = "" if pluginSettings is not None: for name, plugin in plugins: plugin.onDisabled(currentTheme, pluginSettings[name], pluginSettings) else: if isinstance(theme.rules, str): theme.rules = theme.rules.decode('utf-8') if isinstance(theme.absolutePrefix, str): theme.absolutePrefix = theme.absolutePrefix.decode('utf-8') if isinstance(theme.__name__, str): theme.__name__ = theme.__name__.decode('utf-8') settings.currentTheme = theme.__name__ settings.rules = theme.rules settings.absolutePrefix = theme.absolutePrefix settings.parameterExpressions = theme.parameterExpressions settings.doctype = theme.doctype if pluginSettings is not None: for name, plugin in plugins: plugin.onDisabled(currentTheme, pluginSettings[name], pluginSettings) currentTheme = settings.currentTheme themeDirectory = queryResourceDirectory(THEME_RESOURCE_NAME, currentTheme) if themeDirectory is not None: plugins = getPlugins() pluginSettings = getPluginSettings(themeDirectory, plugins) if pluginSettings is not None: for name, plugin in plugins: plugin.onEnabled(currentTheme, pluginSettings[name], pluginSettings) policy.set_theme(currentTheme, theme)
def applyTheme(theme): """Apply an ITheme """ # on write, force using default policy policy = IThemingPolicy(NoRequest()) settings = policy.getSettings() plugins = None themeDirectory = None pluginSettings = None currentTheme = policy.getCurrentTheme() if currentTheme is not None: themeDirectory = queryResourceDirectory( THEME_RESOURCE_NAME, currentTheme) if themeDirectory is not None: plugins = getPlugins() pluginSettings = getPluginSettings(themeDirectory, plugins) if theme is None: settings.currentTheme = None settings.rules = None settings.absolutePrefix = None settings.parameterExpressions = {} settings.doctype = "" if pluginSettings is not None: for name, plugin in plugins: plugin.onDisabled(currentTheme, pluginSettings[name], pluginSettings) else: if not isinstance(theme.rules, six.text_type): theme.rules = theme.rules.decode('utf-8') if not isinstance(theme.absolutePrefix, six.text_type): theme.absolutePrefix = theme.absolutePrefix.decode('utf-8') if not isinstance(theme.__name__, six.text_type): theme.__name__ = theme.__name__.decode('utf-8') settings.currentTheme = theme.__name__ settings.rules = theme.rules settings.absolutePrefix = theme.absolutePrefix settings.parameterExpressions = theme.parameterExpressions settings.doctype = theme.doctype if pluginSettings is not None: for name, plugin in plugins: plugin.onDisabled(currentTheme, pluginSettings[name], pluginSettings) currentTheme = settings.currentTheme themeDirectory = queryResourceDirectory( THEME_RESOURCE_NAME, currentTheme) if themeDirectory is not None: plugins = getPlugins() pluginSettings = getPluginSettings(themeDirectory, plugins) if pluginSettings is not None: for name, plugin in plugins: plugin.onEnabled(currentTheme, pluginSettings[name], pluginSettings) policy.set_theme(currentTheme, theme)