def _outer(func):

        @wraps(func)
        def _inner(sender, **kwargs):
            context = kwargs.get('context', None)
            kwargs['content'].append(func(context))
            return func

        for name in names:
            registry.connect(name, _inner)

        return _inner
Exemple #2
0
    def test_implicit_registration(self):
        """Register a hook implicitly."""

        mycontext = {}
        result = u"I am Dave! Yognaught."

        def _myhook(sender, **kwargs):
            context = kwargs.get('context')
            assert id(mycontext) == id(context)
            kwargs['content'].append(result)

        registry.connect('myhook', _myhook)
        self.assertEquals(result, registry.get_content('myhook', mycontext))
Exemple #3
0
    def test_signals(self):
        """Make sure the signals are fired."""

        _signals_fired = []

        def _connect_sidebar(sender, **kwargs):
            _signals_fired.append('sidebar')

        def _connect_header(sender, **kwargs):
            _signals_fired.append('header')

        registry.connect('sidebar_start', _connect_sidebar)
        registry.connect('header_end', _connect_header)

        self.client.get('/')
        self.assertEquals(len(_signals_fired), 2)
        self.assertTrue('sidebar' in _signals_fired)
        self.assertTrue('header' in _signals_fired)
from .views import _render_sidebar_entry, _render_heading
from templatehooks.registry import registry
from templatehooks.decorators import hook


def _connect_level_heading(sender, **kwargs):
    kwargs['content'].append(_render_heading())


def _connect_sidebar_entry(sender, **kwargs):
    request = kwargs['context']['request']
    kwargs['content'].append(_render_sidebar_entry(request))


@hook('header_end')
def _render_second_heading(context):
    return u"<p>Hello from decorator!</p>"


@hook('header_end', 'sidebar_start')
def _render_multiple_hooks(context):
    return u"<p>Multiple hooks via decorator.</p>"


registry.connect('header_end', _connect_level_heading)
registry.connect('sidebar_start', _connect_sidebar_entry)