Example #1
0
    def wrap_controller(self, func, controller=None):
        """Registers a TurboGears controller wrapper.

        Controller Wrappers are much like a **decorator** applied to
        every controller.
        They receive :class:`tg.configuration.AppConfig` instance
        as an argument and the next handler in chain and are expected
        to return a new handler that performs whatever it requires
        and then calls the next handler.

        A simple example for a controller wrapper is a simple logging wrapper::

            def controller_wrapper(app_config, caller):
                def call(*args, **kw):
                    try:
                        print 'Before handler!'
                        return caller(*args, **kw)
                    finally:
                        print 'After Handler!'
                return call

            tg.hooks.wrap_controller(controller_wrapper)

        It is also possible to register wrappers for a specific controller::

            tg.hooks.wrap_controller(controller_wrapper, controller=RootController.index)

        """
        if environment_loaded.reached:
            raise TGConfigError(
                'Controller wrappers can be registered only at '
                'configuration time.')

        if controller is None:
            environment_loaded.register(
                _ApplicationHookRegistration('controller_wrapper', func))
        else:
            controller = default_im_func(controller)
            registration = _ControllerHookRegistration(controller,
                                                       'controller_wrapper',
                                                       func)
            renderers_ready.register(registration)
Example #2
0
    def wrap_controller(self, func, controller=None):
        """Registers a TurboGears controller wrapper.

        Controller Wrappers are much like a **decorator** applied to
        every controller.
        They receive :class:`tg.configuration.AppConfig` instance
        as an argument and the next handler in chain and are expected
        to return a new handler that performs whatever it requires
        and then calls the next handler.

        A simple example for a controller wrapper is a simple logging wrapper::

            def controller_wrapper(app_config, caller):
                def call(*args, **kw):
                    try:
                        print 'Before handler!'
                        return caller(*args, **kw)
                    finally:
                        print 'After Handler!'
                return call

            tg.hooks.wrap_controller(controller_wrapper)

        It is also possible to register wrappers for a specific controller::

            tg.hooks.wrap_controller(controller_wrapper, controller=RootController.index)

        """
        if environment_loaded.reached:
            raise TGConfigError('Controller wrappers can be registered only at '
                                'configuration time.')

        if controller is None:
            environment_loaded.register(_ApplicationHookRegistration('controller_wrapper', func))
        else:
            controller = default_im_func(controller)
            registration = _ControllerHookRegistration(controller, 'controller_wrapper', func)
            renderers_ready.register(registration)
Example #3
0
    Sart Tracim daemons
    """
    from tg import config
    cfg = CFG.get_instance()
    # Don't start daemons if they are disabled
    if config.get('disable_daemons', False):
        return

    manager.run('radicale', RadicaleDaemon)
    manager.run('webdav', WsgiDavDaemon)

    if cfg.EMAIL_PROCESSING_MODE == CFG.CST.ASYNC:
        manager.run('mail_sender', MailSenderDaemon)


environment_loaded.register(lambda: start_daemons(daemons))
interrupt_manager = InterruptManager(os.getpid(), daemons_manager=daemons)

# Note: here are fake translatable strings that allow to translate messages for reset password email content
duplicated_email_subject = l_('Password reset request')
duplicated_email_body = l_('''
We've received a request to reset the password for this account.
Please click this link to reset your password:

%(password_reset_link)s

If you no longer wish to make the above change, or if you did not initiate this request, please disregard and/or delete this e-mail.
''')

#######
#
Example #4
0
    if cfg.EMAIL_PROCESSING_MODE == CFG.CST.ASYNC:
        manager.run('mail_sender', MailSenderDaemon)


def configure_depot():
    """Configure Depot."""
    depot_storage_name = CFG.get_instance().DEPOT_STORAGE_NAME
    depot_storage_path = CFG.get_instance().DEPOT_STORAGE_DIR
    depot_storage_settings = {'depot.storage_path': depot_storage_path}
    DepotManager.configure(
        depot_storage_name,
        depot_storage_settings,
    )


environment_loaded.register(lambda: start_daemons(daemons))
environment_loaded.register(lambda: configure_depot())

interrupt_manager = InterruptManager(os.getpid(), daemons_manager=daemons)

#######
#
# INFO - D.A. - 2014-10-31
# fake strings allowing to translate resetpassword tgapp.
# TODO - Integrate these translations into tgapp-resetpassword
#

l_('New password')
l_('Confirm new password')
l_('Save new password')
l_('Email address')
Example #5
0
daemons = DaemonsManager()


def start_daemons(manager: DaemonsManager):
    """
    Sart Tracim daemons
    """
    from tg import config
    # Don't start daemons if they are disabled
    if 'disable_daemons' in config and config['disable_daemons']:
        return

    manager.run('radicale', RadicaleDaemon)
    manager.run('webdav', WsgiDavDaemon)

environment_loaded.register(lambda: start_daemons(daemons))

# Note: here are fake translatable strings that allow to translate messages for reset password email content
duplicated_email_subject = l_('Password reset request')
duplicated_email_body = l_('''
We've received a request to reset the password for this account.
Please click this link to reset your password:

%(password_reset_link)s

If you no longer wish to make the above change, or if you did not initiate this request, please disregard and/or delete this e-mail.
''')

#######
#
# INFO - D.A. - 2014-10-31
Example #6
0
    if cfg.EMAIL_PROCESSING_MODE == CFG.CST.ASYNC:
        manager.run('mail_sender', MailSenderDaemon)


def configure_depot():
    """Configure Depot."""
    depot_storage_name = CFG.get_instance().DEPOT_STORAGE_NAME
    depot_storage_path = CFG.get_instance().DEPOT_STORAGE_DIR
    depot_storage_settings = {'depot.storage_path': depot_storage_path}
    DepotManager.configure(
        depot_storage_name,
        depot_storage_settings,
    )


environment_loaded.register(lambda: start_daemons(daemons))
environment_loaded.register(lambda: configure_depot())

interrupt_manager = InterruptManager(os.getpid(), daemons_manager=daemons)

#######
#
# INFO - D.A. - 2014-10-31
# fake strings allowing to translate resetpassword tgapp.
# TODO - Integrate these translations into tgapp-resetpassword
#

l_('New password')
l_('Confirm new password')
l_('Save new password')
l_('Email address')