How to use the feincms3.apps.reverse_app 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 / models.py View on Github external
def get_absolute_url(self):
        return reverse_app(
            (self.category, "articles"), "article-detail", kwargs={"pk": self.pk}
        )
github matthiask / feincms3 / tests / testapp / test_feincms3.py View on Github external
with override_urlconf(apps_urlconf()):
            article = Article.objects.order_by("pk").first()
            with override("de"):
                self.assertEqual(
                    article.get_absolute_url(), "/de/publications/%s/" % article.pk
                )

            with override("en"):
                self.assertEqual(
                    article.get_absolute_url(), "/en/publications/%s/" % article.pk
                )

                # The german URL is returned when specifying the ``languages``
                # list explicitly.
                self.assertEqual(
                    reverse_app(
                        (article.category, "articles"),
                        "article-detail",
                        kwargs={"pk": article.pk},
                        languages=["de", "en"],
                    ),
                    "/de/publications/%s/" % article.pk,
                )

        response = self.client.get("/de/publications/%s/" % article.pk)
        self.assertContains(response, "<h1>publications 0</h1>", 1)

        # The exact value of course does not matter, just the fact that the
        # value does not change all the time.
        self.assertEqual(apps_urlconf(), "urlconf_fe9552a8363ece1f7fcf4970bf575a47")
github matthiask / feincms3 / tests / testapp / models.py View on Github external
def get_absolute_url(self):
        with override(self.language_code):
            return reverse_app("translated-articles", "detail", kwargs={"pk": self.pk})
github matthiask / feincms3 / feincms3 / templatetags / feincms3.py View on Github external
def render(self, context):
        args = [arg.resolve(context) for arg in self.args]
        kwargs = {k: v.resolve(context) for k, v in self.kwargs.items()}
        namespaces = self.namespaces.resolve(context)
        view_name = self.view_name.resolve(context)
        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:
github matthiask / feincms3-example / app / articles / models.py View on Github external
- fr.publications.article-detail
        - fr.articles.article-detail
        - de.publications.article-detail
        - de.articles.article-detail
        - en.publications.article-detail
        - en.articles.article-detail
        - Otherwise, let the NoReverseMatch exception bubble.

        reverse_app tries harder returning an URL in the correct
        language than returning an URL for the correct app. Better
        show a PR publication on the blog page than switching
        languages.
        """

        return reverse_app(
            (self.category, 'articles'),
            'article-detail',
            kwargs={
                'year': self.publication_date.year,
                'slug': self.slug,
            },