How to use the wagtail.core.blocks.StructBlock function in wagtail

To help you get started, we’ve selected a few wagtail 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 liqd / a4-opin / home / migrations / 0024_add_maltese.py View on Github external
import wagtail.images.blocks
import wagtail.core.fields
import wagtail.embeds.blocks


class Migration(migrations.Migration):

    dependencies = [
        ('home', '0023_merge'),
    ]

    operations = [
        migrations.AddField(
            model_name='homepage',
            name='body_mt',
            field=wagtail.core.fields.StreamField((('image', wagtail.images.blocks.ImageChooserBlock(icon='image')), ('info_block', wagtail.core.blocks.StructBlock((('title', wagtail.core.blocks.CharBlock(required=False, classname='full title')), ('image', wagtail.images.blocks.ImageChooserBlock(required=False)), ('text', wagtail.core.blocks.RichTextBlock(required=False)), ('button', wagtail.core.blocks.StructBlock((('internal_link', wagtail.core.blocks.PageChooserBlock(required=False)), ('external_link', wagtail.core.blocks.URLBlock(required=False)), ('link_text', wagtail.core.blocks.TextBlock(required=False))), required=False)), ('highlight', wagtail.core.blocks.ChoiceBlock(icon='cup', required=False, choices=[('', 'None'), ('highlight', 'Highlight (blue)'), ('boxed', 'Boxed'), ('boxed2', 'Boxed Variation'), ('highlight-purple', 'Highlight (purple)')], help_text='How should this block be displayed?')), ('alignment', wagtail.core.blocks.ChoiceBlock(icon='cup', choices=[('vertical', 'vertical'), ('horizontal', 'horizontal')], help_text='How should the text and image be aligned?'))))), ('video_block', wagtail.core.blocks.StructBlock((('title', wagtail.core.blocks.CharBlock(classname='full title')), ('video', wagtail.embeds.blocks.EmbedBlock())))), ('news_block', wagtail.core.blocks.StructBlock((('title', wagtail.core.blocks.CharBlock(classname='full title')), ('news', wagtail.core.blocks.CharBlock(classname='full title'))))), ('rss_feed', wagtail.core.blocks.StructBlock((('feed', wagtail.snippets.blocks.SnippetChooserBlock(required=True, target_model=home.models.snippets.RSSImport)),))), ('column_block', wagtail.core.blocks.StructBlock((('title_col1', wagtail.core.blocks.CharBlock(required=False, classname='full title')), ('image_col1', wagtail.images.blocks.ImageChooserBlock(required=False)), ('text_col1', wagtail.core.blocks.RichTextBlock(required=False)), ('title_col2', wagtail.core.blocks.CharBlock(required=False, classname='full title')), ('image_col2', wagtail.images.blocks.ImageChooserBlock(required=False)), ('text_col2', wagtail.core.blocks.RichTextBlock(required=False)), ('title_col3', wagtail.core.blocks.CharBlock(required=False, classname='full title')), ('image_col3', wagtail.images.blocks.ImageChooserBlock(required=False)), ('text_col3', wagtail.core.blocks.RichTextBlock(required=False)))))), blank=True, null=True),
        ),
        migrations.AddField(
            model_name='homepage',
            name='intro_mt',
            field=models.CharField(default='Ever wondered how to get young people involved in politics online?OPIN, a European toolbox for youth eParticipation projects, shows you how.', blank=True, max_length=255, verbose_name='Subtitle'),
        ),
        migrations.AddField(
            model_name='homepage',
            name='title_mt',
            field=models.CharField(blank=True, max_length=255, verbose_name='Header Title'),
        ),
        migrations.AddField(
            model_name='manualsdetailpage',
            name='body_mt',
            field=wagtail.core.fields.StreamField((('heading', wagtail.core.blocks.CharBlock(icon='title', classname='full title')), ('paragraph', wagtail.core.blocks.TextBlock(icon='pilcrow')), ('rich_text', wagtail.core.blocks.RichTextBlock(icon='pilcrow')), ('video_block', wagtail.core.blocks.StructBlock((('title', wagtail.core.blocks.CharBlock(classname='full title')), ('video', wagtail.embeds.blocks.EmbedBlock())))), ('image', wagtail.images.blocks.ImageChooserBlock(icon='image')), ('accordion_block', wagtail.core.blocks.StructBlock((('accordion_items', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock((('title', wagtail.core.blocks.TextBlock(required=False)), ('content', wagtail.core.blocks.RichTextBlock(required=False)))))),), icon='collapse-down'))), blank=True, verbose_name='body', null=True),
        ),
github mdn / developer-portal / developerportal / apps / home / migrations / 0016_auto_20190628_1437.py View on Github external
operations = [
        migrations.AlterField(
            model_name="homepage",
            name="featured",
            field=wagtail.core.fields.StreamField(
                [
                    (
                        "article",
                        wagtail.core.blocks.PageChooserBlock(
                            page_type=["articles.Article"], required=False
                        ),
                    ),
                    (
                        "external_page",
                        wagtail.core.blocks.StructBlock(
                            [
                                ("url", wagtail.core.blocks.URLBlock()),
                                ("title", wagtail.core.blocks.CharBlock()),
                                (
                                    "intro",
                                    wagtail.core.blocks.TextBlock(required=False),
                                ),
                                (
                                    "header_image",
                                    wagtail.images.blocks.ImageChooserBlock(
                                        label="Image"
                                    ),
                                ),
                            ],
                            help_text="Details of an external page",
                        ),
github FlipperPA / wagtailcontentstream / wagtailcontentstream / blocks.py View on Github external
table = TableBlock(icon='table')
    code = CodeBlock(icon='code')

    class Meta:
        help_text = 'The main page body.'


class ContentStreamBlockWithRawCode(ContentStreamBlock):
    raw_code = CodeBlock(
        icon='code',
        language='html',
        template='wagtailcodeblock/raw_code.html',
    )


class SectionStructBlock(StructBlock):
    """
    Contains the elements we'll want to have in a Sectioned Content Stream block.
    """
    section_heading = TextBlock(
        icon='title',
        help_text='Heading for this section.',
    )
    body = ContentStreamBlock(
        help_text='The body content goes here.',
    )

    class Meta:
        template = 'wagtailcontentstream/blocks/section_struct_block.html'
        icon = 'doc-full-inverse'
github mdn / developer-portal / developerportal / apps / topics / migrations / 0021_auto_20190701_1105.py View on Github external
import wagtail.images.blocks


class Migration(migrations.Migration):

    dependencies = [("topics", "0020_auto_20190701_1104")]

    operations = [
        migrations.AlterField(
            model_name="topic",
            name="get_started",
            field=wagtail.core.fields.StreamField(
                [
                    (
                        "panel",
                        wagtail.core.blocks.StructBlock(
                            [
                                ("title", wagtail.core.blocks.CharBlock()),
                                ("image", wagtail.images.blocks.ImageChooserBlock()),
                                ("description", wagtail.core.blocks.TextBlock()),
                                ("button_text", wagtail.core.blocks.CharBlock()),
                                (
                                    "page_link",
                                    wagtail.core.blocks.PageChooserBlock(
                                        required=False
                                    ),
                                ),
                                (
                                    "external_link",
                                    wagtail.core.blocks.URLBlock(required=False),
                                ),
github thepoly / pipeline / core / models.py View on Github external
name = models.CharField(max_length=255)
    election_site_id = models.IntegerField(default=-1)
    autocomplete_search_field = "name"

    def autocomplete_label(self):
        return self.name

    @classmethod
    def autocomplete_create(kls: type, value: str):
        return kls.objects.create(name=value)

    def __str__(self):
        return self.name


class CandidateBlock(StructBlock):
    image = ImageChooserBlock()
    caption = RichTextBlock(features=["italic"], required=False)


@register_snippet
class Position(models.Model):
    title = models.CharField(max_length=100)

    def __str__(self):
        return self.title


@register_snippet
class Term(Orderable, models.Model):
    position = models.ForeignKey(
        Position, on_delete=models.PROTECT, related_name="terms"
github TakwimuAfrica / Takwimu / takwimu / models / dashboard.py View on Github external
"'Find Out More' button URL", default="https://takwimu.zendesk.com/")
    cta_two_name = models.TextField(
        "Second button Name (optional)", blank=True)
    cta_two_url = models.URLField("Second button URL (optional)", blank=True)

    search_fields = [
        index.SearchField('question'),
        index.SearchField('answer'),
    ]

    def __str__(self):
        return self.question.encode('ascii', 'ignore')


# HURUmap style widget for FeaturedData.
class FeaturedDataWidgetBlock(blocks.StructBlock):
    title = blocks.CharBlock(required=True, default="")
    data_country = blocks.ChoiceBlock(required=True,
                                 choices=[
                                     ('ET', 'Ethiopia'),
                                     ('KE', 'Kenya'),
                                     ('NG', 'Nigeria'),
                                     ('SN', 'Senegal'),
                                     ('TZ', 'Tanzania'),
                                 ],
                                 label='Country')
    data_id = blocks.ChoiceBlock(required=True,
                                 choices=HURUMAP_DATA_DISTS,
                                 label='Data')
    chart_type = blocks.ChoiceBlock(required=True,
                                    choices=[
                                        ('histogram', 'Histogram'),
github torchbox / wagtail-grapple / grapple / types / streamfield.py View on Github external
def resolve_blocks(self, info, **kwargs):
        stream_blocks = []
        for field in self.value.stream_data:
            block = self.value.stream_block.child_blocks[field["type"]]
            if not issubclass(type(block), blocks.StructBlock):
                value = block.to_python(field["value"])

            stream_blocks.append(StructBlockItem(field["type"], block, field["value"]))
        return stream_blocks
github mdn / developer-portal / developerportal / apps / externalcontent / migrations / 0016_auto_20190731_1226.py View on Github external
operations = [
        migrations.AddField(
            model_name="externalarticle",
            name="authors",
            field=wagtail.core.fields.StreamField(
                [
                    (
                        "author",
                        wagtail.core.blocks.PageChooserBlock(
                            page_type=["people.Person"]
                        ),
                    ),
                    (
                        "external_author",
                        wagtail.core.blocks.StructBlock(
                            [
                                ("title", wagtail.core.blocks.CharBlock(label="Name")),
                                ("image", wagtail.images.blocks.ImageChooserBlock()),
                                (
                                    "url",
                                    wagtail.core.blocks.URLBlock(
                                        label="URL", required=False
                                    ),
                                ),
                            ]
                        ),
                    ),
                ],
                blank=True,
                null=True,
            ),
github uno-isqa-8950 / uno-cpi / home / blocks.py View on Github external
icon = 'placeholder'
        label = 'Two Columns'
        template = "blocks/two_column_block.html"

class ThreeColumnBlock(StructBlock):

    left_column = RichTextBlock(icon='arrow-right', label='Left column content')
    middle_column = RichTextBlock(icon='arrow-up', label='Middle column content')
    right_column = RichTextBlock(icon='arrow-right', label='Right column content')

    class Meta:
        icon = 'placeholder'
        label = 'Three Columns'
        template = "blocks/three_column_block.html"

class ImageBlock(StructBlock):
    """
    Custom `StructBlock` for utilizing images with associated caption and
    attribution data
    """
    image = ImageChooserBlock(required=True)
    caption = CharBlock(required=False)
    attribution = CharBlock(required=False)

    class Meta:
        icon = 'image'
        template = "blocks/image_block.html"


class HeadingBlock(StructBlock):
    """
    Custom `StructBlock` that allows the user to select h2 - h4 sizes for headers
github torchbox / wagtail-grapple / example / home / migrations / 0011_auto_20190819_1332.py View on Github external
operations = [
        migrations.AlterField(
            model_name="blogpage",
            name="body",
            field=wagtail.core.fields.StreamField(
                [
                    ("heading", wagtail.core.blocks.CharBlock(classname="full title")),
                    ("paragraph", wagtail.core.blocks.RichTextBlock()),
                    ("image", wagtail.images.blocks.ImageChooserBlock()),
                    ("decimal", wagtail.core.blocks.DecimalBlock()),
                    ("date", wagtail.core.blocks.DateBlock()),
                    ("datetime", wagtail.core.blocks.DateTimeBlock()),
                    (
                        "gallery",
                        wagtail.core.blocks.StructBlock(
                            [
                                (
                                    "title",
                                    wagtail.core.blocks.CharBlock(
                                        classname="full title"
                                    ),
                                ),
                                (
                                    "images",
                                    wagtail.core.blocks.StreamBlock(
                                        [
                                            (
                                                "image",
                                                wagtail.core.blocks.StructBlock(
                                                    [
                                                        (