Skip to main content

Register wagtailblocks with a simple decorator

Project description

Wagtailblock Register

Usage

Add in settings.py.

# Default WAGTAILBLOCK_COLLECTOR = "blocks"
WAGTAILBLOCK_COLLECTOR = "itemblocks"

String in WAGTAILBLOCK_COLLECTOR is a file. Default collector file is blocks.py.

Wagtailblock register will search for the file.

Add block to collector

Above each block in the collectors file add @register_block

Example:

from wagtailblock_register import register_block
from wagtail.core import blocks
from wagtail.images.blocks import ImageChooserBlock

@register_block
class ImageTextBlock(blocks.StructBlock):
    image = ImageChooserBlock(label="Afbeelding")
    text = blocks.TextBlock(label="Tekst")
    text_color = blocks.CharBlock(default="#007BFF", label="Tekst kleur")
    position = blocks.ChoiceBlock(choices=(('left','Tekst links, afbeelding rechts'), ('right','Tekst rechts, afbeelding links')), label="Positioneren")

    class Meta:
        template = "website/blocks/tekst_image.html"
        icon = "image"
        label = "Afbeelding met tekst"

Call all blocks in models.py

Example:

from wagtail.core.models import Page

from wagtail.core.fields import RichTextField, StreamField
from wagtail.admin.edit_handlers import StreamFieldPanel

from wagtailblock_register import call_blocks


class ContentPage(Page):
    template = "website/pages/content.html"

    body = StreamField(call_blocks(), null=True)

    content_panels = Page.content_panels + [
        StreamFieldPanel("body"),
    ]

    class Meta:
        verbose_name_plural = "Content pagina"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wagtailblock-register-1.0.tar.gz (3.0 kB view hashes)

Uploaded Source

Built Distribution

wagtailblock_register-1.0-py3-none-any.whl (3.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page