How to use the feincms3.regions.Regions 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
parent=page, ordering=10, region="main", html="<b>Hello</b>"
        )

        regions = Regions.from_item(page, renderer=renderer)
        self.assertEqual(regions.render("main", Context()), "<b>Hello</b>\n")

        regions = Regions.from_item(page, renderer=renderer)
        self.assertEqual(
            regions.render("main", Context({"outer": "Test"})), "<b>Hello</b>Test\n"
        )

        regions = Regions.from_item(page, renderer=renderer, timeout=3)
        self.assertEqual(
            regions.render("main", Context({"outer": "Test2"})), "<b>Hello</b>Test2\n"
        )
        regions = Regions.from_item(page, renderer=renderer, timeout=3)
        # Output stays the same.
        self.assertEqual(
            regions.render("main", Context({"outer": "Test3"})), "<b>Hello</b>Test2\n"
        )

        self.assertEqual(regions.cache_key("main"), "testapp.page-%s-main" % page.pk)
github matthiask / feincms3 / tests / testapp / views.py View on Github external
def page_detail(request, path=None):
    page = get_object_or_404(
        Page.objects.active(), path=("/%s/" % path) if path else "/"
    )
    page.activate_language(request)

    if page.redirect_to_url or page.redirect_to_page:
        return redirect(page.redirect_to_url or page.redirect_to_page)

    return render(
        request,
        page.template.template_name,
        {
            "page": page,
            "regions": Regions.from_item(
                item=page, renderer=renderer, inherit_from=page.ancestors().reverse()
            ),
github matthiask / feincms3 / tests / testapp / test_feincms3.py View on Github external
def test_standalone_renderer(self):
        """The renderer also works when used without a wrapping template"""

        renderer = TemplatePluginRenderer()
        renderer.register_template_renderer(
            HTML, ["renderer/html.html", "renderer/html.html"]
        )

        page = Page.objects.create(template_key="standard")
        HTML.objects.create(
            parent=page, ordering=10, region="main", html="<b>Hello</b>"
        )

        regions = Regions.from_item(page, renderer=renderer)
        self.assertEqual(regions.render("main", Context()), "<b>Hello</b>\n")

        regions = Regions.from_item(page, renderer=renderer)
        self.assertEqual(
            regions.render("main", Context({"outer": "Test"})), "<b>Hello</b>Test\n"
        )

        regions = Regions.from_item(page, renderer=renderer, timeout=3)
        self.assertEqual(
            regions.render("main", Context({"outer": "Test2"})), "<b>Hello</b>Test2\n"
        )
        regions = Regions.from_item(page, renderer=renderer, timeout=3)
        # Output stays the same.
        self.assertEqual(
            regions.render("main", Context({"outer": "Test3"})), "<b>Hello</b>Test2\n"
        )
github matthiask / feincms3 / tests / testapp / test_newregions.py View on Github external
def test_restart_subregion(self):
        class RestartRegions(Regions):
            def handle_restart(self, items, context):
                first = True
                yield '<div class="stuff">'
                while True:
                    yield self.renderer.render_plugin_in_context(
                        items.popleft(), context
                    )
                    # Item isn't the first and explicitly specifies
                    # subregion="restart", restart subregion
                    if (
                        not first
                        and items
                        and matches(items[0], subregions={None, "restart"})
                    ):
                        break
</div>
github matthiask / feincms3 / tests / testapp / test_newregions.py View on Github external
subregion = ""


class File(SimpleNamespace):
    pass


renderer = TemplatePluginRenderer()
renderer.register_string_renderer(Text, lambda plugin: plugin.text)
renderer.register_string_renderer(Teaser, lambda plugin: plugin.text)
renderer.register_string_renderer(FAQ, lambda plugin: plugin.text)
renderer.register_string_renderer(File, lambda plugin: plugin.text)
renderer.register_string_renderer(Command, "")


class MyRegions(Regions):
    def handle_teasers(self, items, context):
        yield '<div class="teasers">'
        while True:
            yield self.renderer.render_plugin_in_context(items.popleft(), context)
            if not items or not matches(items[0], plugins=(Teaser,)):
                break
        yield "</div>"

    def handle_faq(self, items, context):
        yield '<div class="faq">'
        while True:
            yield self.renderer.render_plugin_in_context(items.popleft(), context)
            if not items or not matches(
                items[0], plugins=(FAQ, File), subregions={None, "faq"}
            ):
                break</div>
github matthiask / feincms3-example / app / pages / views.py View on Github external
def page_detail(request, path=None):
    page = get_object_or_404(
        Page.objects.active(),
        path='/{}/'.format(path) if path else '/',
    )
    page.activate_language(request)
    return render(request, page.template.template_name, {
        'page': page,
        'regions': Regions.from_item(
            page, renderer=renderer, inherit_from=page.ancestors().reverse()),
    })