def test_call(self): def template_hock_mock(*args, **kwargs): self._args = args self._kwargs = kwargs return "ok" # empty hook self.assertListEqual(hook("foo-hook"), []) hook._registry["foo-hook"] = template_hock_mock response = hook("foo-hook", "foo", extra="bar") self.assertEqual(response, "ok") self.assertEqual(self._args, ("foo", )) self.assertDictEqual(self._kwargs, {'extra': "bar", })
def test_call(self): def template_hock_mock(*args, **kwargs): self._args = args self._kwargs = kwargs return "ok" # empty hook self.assertListEqual(hook("foo-hook"), []) hook._registry["foo-hook"] = template_hock_mock response = hook("foo-hook", "foo", extra="bar") self.assertEqual(response, "ok") self.assertEqual(self._args, ("foo", )) self.assertDictEqual(self._kwargs, { 'extra': "bar", })
def hook_tag(context, name, *args, **kwargs): """ Hook tag to call within templates :param dict context: This is automatically passed,\ contains the template state/variables :param str name: The hook which will be dispatched :param \*args: Positional arguments, will be passed to hook callbacks :param \*\*kwargs: Keyword arguments, will be passed to hook callbacks :return: A concatenation of all callbacks\ responses marked as safe (conditionally) :rtype: str """ return format_html_join( sep="\n", format_string="{}", args_generator=((response, ) for response in hook(name, context, *args, **kwargs)))
def hook_tag(context, name, *args, **kwargs): """ Hook tag to call within templates :param dict context: This is automatically passed,\ contains the template state/variables :param str name: The hook which will be dispatched :param \*args: Positional arguments, will be passed to hook callbacks :param \*\*kwargs: Keyword arguments, will be passed to hook callbacks :return: A concatenation of all callbacks\ responses marked as safe (conditionally) :rtype: str """ return format_html_join( sep="\n", format_string="{}", args_generator=( (response, ) for response in hook(name, context, *args, **kwargs) ) )