From 731a434b8e61ea77175afdd6f7c0f5afc10fe36c Mon Sep 17 00:00:00 2001 From: Alessandro Molina Date: Mon, 4 Mar 2024 17:51:59 +0100 Subject: [PATCH] Remove builtin support for Tw2, now in charge of tgext.tw2 --- tg/configurator/components/toscawidgets2.py | 101 -------------------- tg/configurator/fullstack.py | 9 +- 2 files changed, 1 insertion(+), 109 deletions(-) delete mode 100644 tg/configurator/components/toscawidgets2.py diff --git a/tg/configurator/components/toscawidgets2.py b/tg/configurator/components/toscawidgets2.py deleted file mode 100644 index 78614ca5..00000000 --- a/tg/configurator/components/toscawidgets2.py +++ /dev/null @@ -1,101 +0,0 @@ -# -*- coding: utf-8 -*- -from tg.support.converters import asbool - -from ...configuration.utils import TGConfigError -from ..base import (ConfigurationComponent, - BeforeConfigConfigurationAction, AppReadyConfigurationAction) - -from logging import getLogger -log = getLogger(__name__) - - -class ToscaWidgets2ConfigurationComponent(ConfigurationComponent): - """Support for ToscaWidgets2 based Widgets, Forms and Resources. - - Options: - - * ``tw2.enabled``: Enable ToscaWidgets2 support. - For backward compatibility also ``prefer_toscawidgets2`` - and ``use_toscawidgets2`` options are supported. - * ``custom_tw2_config``: Additional TW2 Middleware options to provide. - This should be a dictionary of options. - - Some options from other components influence TW2 behaviour too: - - * ``auto_reload_templates``: Enable autoreloading of Widgets templates. - * ``debug``: Enable debug mode for TW2 (also injects debug resources). - * ``default_renderer``: Rendering Engine used to render Widgets templates. - * ``renderers``: Rendering engines that can be used to render Widgets templates. - - """ - id = 'tw2' - - def get_defaults(self): - return { - 'tw2.enabled': False, - 'custom_tw2_config': {} - } - - def get_coercion(self): - return { - 'tw2.enabled': asbool, - 'prefer_toscawidgets2': asbool, - 'use_toscawidgets2': asbool - } - - def get_actions(self): - return ( - BeforeConfigConfigurationAction(self._configure), - AppReadyConfigurationAction(self._add_middleware), - ) - - def _configure(self, conf, app): - prefer_tw2 = conf.get('prefer_toscawidgets2') - use_tw2 = conf.get('use_toscawidgets2') - if prefer_tw2 or use_tw2: - # Backward compatibility with <=2.3 options. - conf['tw2.enabled'] = True - - def _add_middleware(self, conf, app): - """Configure the ToscaWidgets2 middleware""" - if not conf['tw2.enabled']: - return app - - from tw2.core.middleware import Config, TwMiddleware - from tg.i18n import ugettext, get_lang - - available_renderers = set(conf.get('renderers', [])) - shared_engines = list(available_renderers & set(Config.preferred_rendering_engines)) - if not shared_engines: - raise TGConfigError( - 'None of the configured rendering engines %s is supported ' - 'by ToscaWidgets2, unable to configure ToscaWidgets.' % available_renderers - ) - - default_renderer = conf.get('default_renderer', None) - if default_renderer in shared_engines: - tw2_engines = [default_renderer] + shared_engines - tw2_default_engine = default_renderer - else: - # If preferred rendering engine is not available in TW2, fallback to another one - tw2_engines = shared_engines - tw2_default_engine = shared_engines[0] - - default_tw2_config = dict(default_engine=tw2_default_engine, - preferred_rendering_engines=tw2_engines, - translator=ugettext, - get_lang=lambda: get_lang(all=False), - auto_reload_templates=conf.get('auto_reload_templates', False), - controller_prefix='/tw2/controllers/', - res_prefix='/tw2/resources/', - debug=conf['debug'], - rendering_extension_lookup={ - 'mako': ['mak', 'mako'], - 'genshi': ['genshi', 'html'], - 'jinja': ['jinja', 'jinja2'], - 'kajiki': ['kajiki', 'xhtml', 'xml'] - }) - - default_tw2_config.update(conf.get('custom_tw2_config', {})) - app = TwMiddleware(app, **default_tw2_config) - return app diff --git a/tg/configurator/fullstack.py b/tg/configurator/fullstack.py index 47bbf6bd..4705bfc8 100644 --- a/tg/configurator/fullstack.py +++ b/tg/configurator/fullstack.py @@ -15,7 +15,6 @@ from .components.i18n import I18NConfigurationComponent from .components.caching import CachingConfigurationComponent from .components.session import SessionConfigurationComponent -from .components.toscawidgets2 import ToscaWidgets2ConfigurationComponent from .components.statics import StaticsConfigurationComponent log = logging.getLogger(__name__) @@ -34,7 +33,6 @@ class FullStackApplicationConfigurator(MinimalApplicationConfigurator): - Authentication - Sessions - Caching - - Widgets (ToscaWidgets2) - Databases (Ming and SQLAlchemy) - Transaction Manager - Custom Error Pages @@ -56,11 +54,6 @@ def __init__(self): self.register(SessionConfigurationComponent) self.register(CachingConfigurationComponent) - # from here on, due to TW2, the response is a generator - # so any middleware that relies on the response to be - # a string needs to be applied before this point. - self.register(ToscaWidgets2ConfigurationComponent) - self.register(MingConfigurationComponent) self.register(SQLAlchemyConfigurationComponent) self.register(TransactionManagerConfigurationComponent) @@ -69,7 +62,7 @@ def __init__(self): self.register(SeekableRequestConfigurationComponent) self.register(SlowRequestsConfigurationComponent) self.register(ErrorReportingConfigurationComponent) - + self.register(StaticsConfigurationComponent, after=True) # Place the debuggers after the registry so that we