How to use feincms3 - 10 common examples

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_subrenderer.py View on Github external
def exit(self, **kwargs):
                yield ""

            def reenter(self, **kwargs):
                yield from self.exit(**kwargs)
                yield from self.enter(**kwargs)

        continue_subrenderer = ContinueSubrenderer()
        continue_subrenderer.register_string_renderer(Text, lambda plugin: plugin.text)
        continue_subrenderer.register_string_renderer(Command, "")

        class RegionsWithContinue(SubrendererRegions):
            subrenderers = {"continue": continue_subrenderer}

        continue_renderer = TemplatePluginRenderer()
        continue_renderer.register_string_renderer(Text, lambda plugin: plugin.text)
        continue_renderer.register_string_renderer(Command, "")

        regions = RegionsWithContinue(
            item=None,
            contents={
                "main": [
                    Text(text="before"),
                    Command(subrenderer="continue"),
                    Text(text="first"),
                    Command(subrenderer="continue"),
                    Text(text="second"),
                    Command(subrenderer=""),
                    Text(text="after"),
                ]
            },
github matthiask / feincms3 / tests / testapp / test_subrenderer.py View on Github external
teaser_renderer = TeaserRenderer()
teaser_renderer.register_string_renderer(Teaser, lambda plugin: plugin.text)
teaser_renderer.register_string_renderer(Command, "")

faq_renderer = FAQRenderer()
faq_renderer.register_string_renderer(FAQ, lambda plugin: plugin.text)
faq_renderer.register_string_renderer(Command, "")
faq_renderer.register_string_renderer(File, lambda plugin: plugin.text)


class Regions(SubrendererRegions):
    subrenderers = {"teasers": teaser_renderer, "faq": faq_renderer}


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


class Test(TestCase):
    def test_enter_exit(self):
        regions = Regions(
            item=None,
            contents={
                "main": [
                    Text(text="Text 1"),
                    Teaser(text="Teaser 1"),
                    Teaser(text="Teaser 2"),
github matthiask / feincms3 / tests / testapp / test_subrenderer.py View on Github external
subrenderer = ""


class File(SimpleNamespace):
    pass


class TeaserRenderer(Subrenderer):
    def enter(self, **kwargs):
        yield '<div class="teasers">'

    def exit(self, **kwargs):
        yield "</div>"


class FAQRenderer(Subrenderer):
    def enter(self, **kwargs):
        yield '<div class="faq">'

    def exit(self, **kwargs):
        yield "</div>"


teaser_renderer = TeaserRenderer()
teaser_renderer.register_string_renderer(Teaser, lambda plugin: plugin.text)
teaser_renderer.register_string_renderer(Command, "")

faq_renderer = FAQRenderer()
faq_renderer.register_string_renderer(FAQ, lambda plugin: plugin.text)
faq_renderer.register_string_renderer(Command, "")
faq_renderer.register_string_renderer(File, lambda plugin: plugin.text)
github matthiask / feincms3 / tests / testapp / test_subrenderer.py View on Github external
def test_continue_subrenderer(self):
        class ContinueSubrenderer(Subrenderer):
            def enter(self, **kwargs):
                yield '<div class="stuff">'

            def exit(self, **kwargs):
                yield "</div>"

            def reenter(self, **kwargs):
                yield from self.exit(**kwargs)
                yield from self.enter(**kwargs)

        continue_subrenderer = ContinueSubrenderer()
        continue_subrenderer.register_string_renderer(Text, lambda plugin: plugin.text)
        continue_subrenderer.register_string_renderer(Command, "")

        class RegionsWithContinue(SubrendererRegions):
            subrenderers = {"continue": continue_subrenderer}
github matthiask / feincms3 / tests / testapp / test_subrenderer.py View on Github external
subrenderer = "teasers"


class FAQ(SimpleNamespace):
    subrenderer = "faq"


class Command(SimpleNamespace):
    subrenderer = ""


class File(SimpleNamespace):
    pass


class TeaserRenderer(Subrenderer):
    def enter(self, **kwargs):
        yield '<div class="teasers">'

    def exit(self, **kwargs):
        yield "</div>"


class FAQRenderer(Subrenderer):
    def enter(self, **kwargs):
        yield '<div class="faq">'

    def exit(self, **kwargs):
        yield "</div>"


teaser_renderer = TeaserRenderer()
github matthiask / feincms3 / tests / testapp / test_feincms3.py View on Github external
def test_move_to_root_first(self):
        root, p1, p2 = self.prepare_for_move()
        client = self.login()

        client.post(
            reverse("admin:testapp_page_move", args=(p2.pk,)),
            {"move_to": "first", "of": ""},
        )

        self.assertEqual(
            [(p.pk, p.parent_id, p.position) for p in Page.objects.all()],
            [(p2.pk, None, 10), (root.pk, None, 20), (p1.pk, root.pk, 10)],
        )
github matthiask / feincms3 / tests / testapp / test_feincms3.py View on Github external
clone_url = reverse("admin:testapp_page_clone", args=(blog.pk,))

        response = client.get(clone_url)
        self.assertContains(response, "_set_content")
        self.assertContains(response, "set_application")

        response = client.post(clone_url, {"target": home.pk, "set_application": True})
        self.assertContains(response, "Apps may not have any descendants in the tree.")

        # The other way round works
        clone_url = reverse("admin:testapp_page_clone", args=(home.pk,))

        response = client.post(clone_url, {"target": blog.pk, "set_application": True})
        self.assertRedirects(
            response, reverse("admin:testapp_page_change", args=(blog.pk,))
        )

        # No apps in tree anymore
        self.assertEqual(Page.objects.exclude(application="").count(), 0)
github matthiask / feincms3 / tests / testapp / test_feincms3.py View on Github external
def test_invalid_parent(self):
        root, p1, p2 = self.prepare_for_move()
        p1.application = "blog"
        p1.save()

        p2 = Page.objects.get(pk=p2.pk)
        p2.parent_id = p1.pk

        # Apps may not have descendants
        self.assertRaises(ValidationError, p2.full_clean)

        client = self.login()
        response = client.post(
            reverse("admin:testapp_page_move", args=(p2.pk,)),
            {"move_to": "first", "of": p1.pk},
        )

        self.assertContains(
            response,
            "<li>Invalid parent: Apps may not have any descendants.</li>",
            status_code=200,
        )
github matthiask / feincms3 / tests / testapp / test_feincms3.py View on Github external
def test_invalid_move(self):
        root, p1, p2 = self.prepare_for_move()
        client = self.login()

        response = client.post(reverse("admin:testapp_page_move", args=(root.pk,)), {})
        self.assertContains(response, "This field is required.", 1)

        response = client.post(
            reverse("admin:testapp_page_move", args=(root.pk,)),
            {"move_to": "first", "of": p1.pk},
        )
        self.assertContains(
            response,
            "Select a valid choice. That choice is not one of the available choices.",  # noqa
        )

        response = client.post(
            reverse("admin:testapp_page_move", args=(root.pk,)),
            {"move_to": "first", "of": root.pk},
        )
        self.assertContains(
github matthiask / feincms3 / tests / testapp / test_feincms3.py View on Github external
is_active=True,
            menu="main",
        )

        home_de.testapp_snippet_set.create(
            template_name="snippet-33.html", ordering=10, region="main"
        )

        client = self.login()
        response = client.post(
            reverse("admin:testapp_page_clone", args=(home_en.pk,)),
            {"target": home_de.pk, "_set_content": True},
        )
        # print(response.content.decode("utf-8"))
        self.assertRedirects(
            response, reverse("admin:testapp_page_change", args=(home_de.pk,))
        )

        self.assertEqual(
            list(home_de.testapp_snippet_set.values_list("template_name", flat=True)),
            ["snippet.html"],
        )