Example #1
0
    def _register_hook(self, hook_name, handler):
        if tg_hooks is None:
            # 2.1+
            self.app_config.register_hook(hook_name, handler)
        elif hasattr(tg_hooks, 'wrap_controller'):
            # 2.3+
            if hook_name == 'controller_wrapper':

                def _accept_decoration(decoration, controller):
                    return handler(controller)

                tg_hooks.wrap_controller(_accept_decoration)
            else:
                tg_hooks.register(hook_name, handler)
        else:
            # 2.4+
            if hook_name == 'controller_wrapper':
                from tg import ApplicationConfigurator
                dispatch = ApplicationConfigurator.current().get_component(
                    'dispatch')
                if dispatch is None:
                    raise RuntimeError(
                        'TurboGears application configured without dispatching'
                    )
                dispatch.register_controller_wrapper(handler)
            else:
                tg_hooks.register(hook_name, handler)
Example #2
0
 def _register_hook(self, hook_name, handler):
     if tg_hooks is None:
         self.app_config.register_hook(hook_name, handler)
     else:
         if hook_name == 'controller_wrapper':
             tg_hooks.wrap_controller(handler)
         else:
             tg_hooks.register(hook_name, handler)
Example #3
0
def enable_debugbar(app_config):
    if isinstance(app_config, ApplicationConfigurator):
        tg_hooks.register('initialized_config', DebugBar(app_config))
    else:
        if tg_hooks is None:
            app_config.register_hook('startup', DebugBar(app_config))
        else:
            tg_hooks.register('startup', DebugBar(app_config))
Example #4
0
def plugme(configurator, options=None):
    if options is None:  # pragma: no cover
        options = {}

    from tg import hooks
    from .plugmailer import SetupMailer, RequestMailerAppWrapper

    hooks.register('before_config', SetupMailer(options))
    configurator.register_wrapper(RequestMailerAppWrapper)
    
    return dict(appid='tgext.mailer')
def plugme(app_config, options):
    if 'mail_subject' in options or 'mail_body' in options or 'mail_rich' in options:
        warnings.warn(
            "mail_* options are now deprecated, use registration.on_complete hook(reg, email_data) "
            "to customize the outgoing email.",
            DeprecationWarning,
            stacklevel=2)

    app_config['_pluggable_registration_config'] = options
    hooks.register('after_config', register_dal_interface)
    milestones.config_ready.register(patch_global_registration)
    return dict(appid='registration', global_helpers=False)
Example #6
0
def plugme(app_config, options):
    try:
        # TG 2.3
        app_config['_pluggable_stroller2_config'] = options
        run_enable_depot = False
        if 'depot_backend_type' not in app_config.keys():
            app_config['depot_backend_type'] = 'depot.io.local.LocalFileStorage'
        if 'depot_storage_path' not in app_config.keys():
            app_config['depot_storage_path'] = depot_photos_path
        if 'depot.product_images.backend' not in app_config.keys():
            app_config['depot.product_images.backend'] = app_config['depot_backend_type']
            run_enable_depot = True
        if 'depot.product_images.backend' not in app_config.keys():
            app_config['depot.product_images.storage_path'] = product_photos_path
            run_enable_depot = True
        if run_enable_depot:
            hooks.register('after_config', enable_depot)
    except TypeError:
        # TG 2.4
        app_config.update_blueprint({
            '_pluggable_stroller2_config': options
        })
        run_enable_depot = False
        try:
            app_config.get_blueprint_value('depot_backend_type')
        except KeyError:
            app_config.update_blueprint({
                'depot_backend_type': 'depot.io.local.LocalFileStorage'
            })
        try:
            app_config.get_blueprint_value('depot_storage_path')
        except KeyError:
            app_config.update_blueprint({
                'depot_storage_path': depot_photos_path
            })
        try:
            app_config.get_blueprint_value('depot.product_images.backend')
        except KeyError:
            app_config.update_blueprint({
                'depot.product_images.backend': 'depot.io.local.LocalFileStorage'
            })
            run_enable_depot = True
        try:
            app_config.get_blueprint_value('depot.product_images.storage_path')
        except KeyError:
            app_config.update_blueprint({
                'depot.product_images.storage_path': product_photos_path
            })
            run_enable_depot = True
        if run_enable_depot:
            hooks.register('after_wsgi_middlewares', enable_depot)
    return dict(appid='commerce', global_helpers=True)
    def __call__(self):
        log.info('>>> Public files path is %s' % config['paths']['static_files'])
        hooks.register('startup', self.on_startup)

        def echo_wrapper_factory(handler, config):
            def echo_wrapper(controller, environ, context):
                log.info('Serving: %s' % context.request.path)
                return handler(controller, environ, context)
            return echo_wrapper

        # Application Wrappers are much like easier WSGI Middleware
        # that get a TurboGears context and return a Response object.
        self.configurator.register_wrapper(echo_wrapper_factory)
Example #8
0
    def __call__(self):
        log.info('>>> Public files path is %s' %
                 config['paths']['static_files'])
        hooks.register('startup', self.on_startup)

        def echo_wrapper_factory(handler, config):
            def echo_wrapper(controller, environ, context):
                log.info('Serving: %s' % context.request.path)
                return handler(controller, environ, context)

            return echo_wrapper

        # Application Wrappers are much like easier WSGI Middleware
        # that get a TurboGears context and return a Response object.
        self.configurator.register_wrapper(echo_wrapper_factory)
Example #9
0
def plugme(configurator, options=None):
    if options is None:  # pragma: no cover
        options = {}

    from tg import hooks
    from .plugmailer import SetupMailer, RequestMailerAppWrapper

    if hasattr(configurator, 'register_wrapper'):
        # TG2.3
        hooks.register('before_config', SetupMailer(options))
        configurator.register_wrapper(RequestMailerAppWrapper)
    else:
        # TG2.4+
        hooks.register('before_wsgi_middlewares', SetupMailer(options))
        configurator.register_application_wrapper(RequestMailerAppWrapper)
    
    return dict(appid='tgext.mailer')
Example #10
0
 def _register_hook(self, hook_name, handler):
     if tg_hooks is None:
         # 2.1+
         self.app_config.register_hook(hook_name, handler)
     elif hasattr(tg_hooks, 'wrap_controller'):
         # 2.3+
         if hook_name == 'controller_wrapper':
             def _accept_decoration(decoration, controller):
                 return handler(controller)
             tg_hooks.wrap_controller(_accept_decoration)
         else:
             tg_hooks.register(hook_name, handler)
     else:
         # 2.4+
         if hook_name == 'controller_wrapper':
             from tg import ApplicationConfigurator
             dispatch = ApplicationConfigurator.current().get_component('dispatch')
             if dispatch is None:
                 raise RuntimeError('TurboGears application configured without dispatching')
             dispatch.register_controller_wrapper(handler)
         else:
             tg_hooks.register(hook_name, handler)
Example #11
0
def plugme(app_config, options):
    app_config['_pluggable_ecommerce_config'] = options
    hooks.register('before_config', setup_global_objects)
    hooks.register('after_config', setup_clean_cart_scheduler)
    hooks.register('after_config', init_paypal)


    return dict(appid='shop', global_helpers=True, plug_bootstrap=False)
Example #12
0
 def __call__(self):
     from tg import hooks
     hooks.register('configure_new_app', self.on_app_configured)
     self._configurator.register_wrapper(_MaintenanceApplicationWrapper)
Example #13
0
def enable_debugbar(app_config):
    if tg_hooks is None:
        app_config.register_hook('startup', DebugBar(app_config))
    else:
        tg_hooks.register('startup', DebugBar(app_config))
Example #14
0
 def __call__(self):
     from tg import hooks
     hooks.register('configure_new_app', self.on_app_configured)
     self._configurator.register_wrapper(_MaintenanceApplicationWrapper)
Example #15
0
def enable_debugbar(app_config):
    if tg_hooks is None:
        app_config.register_hook('startup', DebugBar(app_config))
    else:
        tg_hooks.register('startup', DebugBar(app_config))