How to use the feincms3.apps.NoReverseMatch function in feincms3

To help you get started, we’ve selected a few feincms3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github matthiask / feincms3 / tests / testapp / test_feincms3.py View on Github external
def test_reverse(self):
        """Test all code paths through reverse_fallback and reverse_any"""

        self.assertEqual(reverse_fallback("test", reverse, "not-exists"), "test")
        self.assertEqual(reverse_fallback("test", reverse, "admin:index"), "/admin/")
        self.assertEqual(reverse_any(("not-exists", "admin:index")), "/admin/")
        with self.assertRaisesRegex(
            NoReverseMatch,
            r"Reverse for any of 'not-exists-1', 'not-exists-2' with"
            r" arguments '\[\]' and keyword arguments '{}' not found.",
        ):
            reverse_any(("not-exists-1", "not-exists-2"))
github matthiask / feincms3 / tests / testapp / test_feincms3.py View on Github external
("{% reverse_app 'bla' 'bla' fallback='/test/' %}", "/test/", {}),
            (
                "{% reverse_app 'bla' 'bla' fallback='/test/' as t %}{{ t }}",
                "/test/",
                {},
            ),
            ("{% reverse_app 'bla' 'bla' as t %}{{ t|default:'blub' }}", "blub", {}),
        ]

        with override_urlconf(apps_urlconf()):
            for tpl, out, ctx in tests:
                t = Template("{% load feincms3 %}" + tpl)
                self.assertEqual(t.render(Context(ctx)).strip(), out)

            self.assertRaises(
                NoReverseMatch,
                Template("{% load feincms3 %}{% reverse_app 'a' 'a' %}").render,
                Context(),
            )
github matthiask / feincms3 / feincms3 / templatetags / feincms3.py View on Github external
fallback = kwargs.pop("fallback", None)
        if not isinstance(namespaces, (list, tuple)):
            namespaces = namespaces.split(",")
        # Try to look up the URL. If it fails, raise NoReverseMatch unless the
        # {% reverse ... as var %} construct is used, in which case return
        # nothing.
        url = ""
        try:
            url = apps.reverse_app(
                namespaces,
                view_name,
                args=args,
                kwargs=kwargs,
                current_app=self._current_app(context),
            )
        except apps.NoReverseMatch:
            if fallback is not None:
                url = fallback
            elif self.asvar is None:
                raise

        if self.asvar:
            context[self.asvar] = url
            return ""
        else:
            if context.autoescape:
                url = conditional_escape(url)
            return url