How to use the wagtail.core.blocks.PageChooserBlock 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 CodingForEverybody / learn-wagtail / streams / blocks.py View on Github external
):  # noqa
        super().__init__(**kwargs)
        self.features = ["bold", "italic", "link"]

    class Meta:  # noqa
        template = "streams/richtext_block.html"
        icon = "edit"
        label = "Simple RichText"


class CTABlock(blocks.StructBlock):
    """A simple call to action section."""

    title = blocks.CharBlock(required=True, max_length=60)
    text = blocks.RichTextBlock(required=True, features=["bold", "italic"])
    button_page = blocks.PageChooserBlock(required=False)
    button_url = blocks.URLBlock(required=False)
    button_text = blocks.CharBlock(required=True, default='Learn More', max_length=40)

    class Meta:  # noqa
        template = "streams/cta_block.html"
        icon = "placeholder"
        label = "Call to Action"


class LinkStructValue(blocks.StructValue):
    """Additional logic for our urls."""

    def url(self):
        button_page = self.get('button_page')
        button_url = self.get('button_url')
        if button_page:
github mdn / developer-portal / developerportal / apps / topics / migrations / 0041_auto_20190813_1503.py View on Github external
migrations.AlterField(
            model_name="topic",
            name="tabbed_panels",
            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(
                                        help_text="External URL to link to instead of a page.",
                                        required=False,
                                    ),
                                ),
                            ]
                        ),
                    )
                ],
                blank=True,
                help_text="Optional tabbed panels for linking out to other resources, max. 3",
github torchbox / wagtail-torchbox / tbx / core / migrations / 0097_auto_20180607_1715.py View on Github external
import wagtail.core.blocks
import wagtail.core.fields
import wagtail.images.blocks


class Migration(migrations.Migration):

    dependencies = [
        ('torchbox', '0096_revert_pr97'),
    ]

    operations = [
        migrations.AlterField(
            model_name='servicepage',
            name='streamfield',
            field=wagtail.core.fields.StreamField([(b'paragraph', wagtail.core.blocks.RichTextBlock(icon='pilcrow')), (b'case_studies', wagtail.core.blocks.StructBlock([(b'title', wagtail.core.blocks.CharBlock(required=True)), (b'intro', wagtail.core.blocks.TextBlock(required=True)), (b'case_studies', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('page', wagtail.core.blocks.PageChooserBlock('torchbox.WorkPage')), ('title', wagtail.core.blocks.CharBlock(required=False)), ('descriptive_title', wagtail.core.blocks.CharBlock(required=False)), ('image', wagtail.images.blocks.ImageChooserBlock(required=False))])))])), (b'highlights', wagtail.core.blocks.StructBlock([(b'title', wagtail.core.blocks.CharBlock(required=True)), (b'intro', wagtail.core.blocks.TextBlock(required=False)), (b'highlights', wagtail.core.blocks.ListBlock(wagtail.core.blocks.TextBlock()))])), (b'pull_quote', wagtail.core.blocks.StructBlock([(b'quote', wagtail.core.blocks.CharBlock(classname='quote title')), (b'attribution', wagtail.core.blocks.CharBlock())], template='blocks/pull_quote_block.html')), (b'process', wagtail.core.blocks.StructBlock([(b'title', wagtail.core.blocks.CharBlock(required=True)), (b'intro', wagtail.core.blocks.TextBlock(required=False)), (b'steps', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('subtitle', wagtail.core.blocks.CharBlock(required=False)), ('title', wagtail.core.blocks.CharBlock(required=True)), ('icon', wagtail.core.blocks.CharBlock(help_text='Paste SVG code here', max_length=9000, required=True)), ('description', wagtail.core.blocks.TextBlock(required=True))])))])), (b'people', wagtail.core.blocks.StructBlock([(b'title', wagtail.core.blocks.CharBlock(required=True)), (b'intro', wagtail.core.blocks.TextBlock(required=True)), (b'people', wagtail.core.blocks.ListBlock(wagtail.core.blocks.PageChooserBlock()))])), (b'featured_pages', wagtail.core.blocks.StructBlock([(b'title', wagtail.core.blocks.CharBlock()), (b'pages', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('page', wagtail.core.blocks.PageChooserBlock()), ('image', wagtail.images.blocks.ImageChooserBlock()), ('text', wagtail.core.blocks.TextBlock()), ('sub_text', wagtail.core.blocks.CharBlock(max_length=100))])))])), (b'sign_up_form_page', wagtail.core.blocks.StructBlock([(b'page', wagtail.core.blocks.PageChooserBlock('torchbox.SignUpFormPage'))])), (b'logos', wagtail.core.blocks.StructBlock([(b'title', wagtail.core.blocks.CharBlock()), (b'intro', wagtail.core.blocks.CharBlock()), (b'logos', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock()), ('link_page', wagtail.core.blocks.PageChooserBlock(required=False)), ('link_external', wagtail.core.blocks.URLBlock(required=False))])))]))]),
        ),
github praekeltfoundation / molo / molo / core / migrations / 0002_add_can_view_response_reaction_question_permission.py View on Github external
class Migration(migrations.Migration):

    dependencies = [
        ('core', '0001_squashed_0077_molo_page'),
    ]

    operations = [
        migrations.AlterModelOptions(
            name='reactionquestionresponse',
            options={'permissions': (('can_view_response', 'Can view Response'),)},
        ),
        migrations.AlterField(
            model_name='articlepage',
            name='body',
            field=wagtail.core.fields.StreamField((('heading', wagtail.core.blocks.CharBlock(classname='full title')), ('paragraph', molo.core.blocks.MarkDownBlock()), ('image', wagtail.images.blocks.ImageChooserBlock()), ('list', wagtail.core.blocks.ListBlock(wagtail.core.blocks.CharBlock(label='Item'))), ('numbered_list', wagtail.core.blocks.ListBlock(wagtail.core.blocks.CharBlock(label='Item'))), ('page', wagtail.core.blocks.PageChooserBlock()), ('media', molo.core.models.MoloMediaBlock(icon='media'))), blank=True, null=True),
        ),
        migrations.AlterField(
            model_name='articlepage',
            name='commenting_state',
            field=models.CharField(blank=True, choices=[('O', 'Open'), ('C', 'Closed'), ('D', 'Disabled'), ('T', 'Timestamped')], max_length=1, null=True),
        ),
        migrations.AlterField(
            model_name='articlepage',
            name='social_media_description',
            field=models.TextField(blank=True, null=True, verbose_name='description'),
        ),
        migrations.AlterField(
            model_name='articlepage',
            name='social_media_image',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image', verbose_name='Image'),
        ),
github mozilla / donate-wagtail / donate / navigation / models.py View on Github external
from modelcluster.models import ClusterableModel
from wagtail.admin.edit_handlers import StreamFieldPanel
from wagtail.contrib.settings.models import BaseSetting, register_setting
from wagtail.core import blocks
from wagtail.core.fields import StreamField


class LinkBlock(blocks.StructBlock):
    page = blocks.PageChooserBlock()
    title = blocks.CharBlock(help_text="Leave blank to use the page's own title", required=False)

    class Meta:
        template = 'blocks/menu_item.html',


@register_setting(icon='list-ul')
class NavigationSettings(BaseSetting, ClusterableModel):
    primary_navigation = StreamField(
        [('link', LinkBlock()), ],
        blank=True,
        help_text="Main site navigation"
    )

    panels = [
        StreamFieldPanel('primary_navigation'),
github praekeltfoundation / molo / molo / core / migrations / 0016_richtext_article_body.py View on Github external
import wagtail.core.blocks
import wagtail.core.fields
import wagtail.images.blocks


class Migration(migrations.Migration):

    dependencies = [
        ('core', '0015_freebasics_banner_check'),
    ]

    operations = [
        migrations.AlterField(
            model_name='articlepage',
            name='body',
            field=wagtail.core.fields.StreamField([('heading', wagtail.core.blocks.CharBlock(classname='full title')), ('paragraph', molo.core.blocks.MarkDownBlock()), ('image', wagtail.images.blocks.ImageChooserBlock()), ('list', wagtail.core.blocks.ListBlock(wagtail.core.blocks.CharBlock(label='Item'))), ('numbered_list', wagtail.core.blocks.ListBlock(wagtail.core.blocks.CharBlock(label='Item'))), ('page', wagtail.core.blocks.PageChooserBlock()), ('media', molo.core.models.MoloMediaBlock(icon='media')), ('richtext', wagtail.core.blocks.RichTextBlock())], blank=True, null=True),
        )
github mdn / developer-portal / developerportal / apps / topics / migrations / 0047_rephrase_articles_as_posts.py View on Github external
import wagtail.images.blocks


class Migration(migrations.Migration):

    dependencies = [("topics", "0046_remove_topic_tabbed_panels_title")]

    operations = [
        migrations.AlterField(
            model_name="topic",
            name="featured",
            field=wagtail.core.fields.StreamField(
                [
                    (
                        "post",
                        wagtail.core.blocks.PageChooserBlock(
                            page_type=[
                                "articles.Article",
                                "externalcontent.ExternalArticle",
                            ]
                        ),
                    ),
                    (
                        "external_page",
                        wagtail.core.blocks.StructBlock(
                            [
                                ("url", wagtail.core.blocks.URLBlock()),
                                ("title", wagtail.core.blocks.CharBlock()),
                                (
                                    "description",
                                    wagtail.core.blocks.TextBlock(required=False),
                                ),
github coderedcorp / coderedcms / coderedcms / blocks / html_blocks.py View on Github external
required=True,
        help_text=_('Alternate text to show if the image doesn’t load'),
    )

    class Meta:
        template = 'coderedcms/blocks/image_link_block.html'
        icon = 'image'
        label = _('Image Link')
        value_class = LinkStructValue


class PageListBlock(BaseBlock):
    """
    Renders a preview of selected pages.
    """
    indexed_by = blocks.PageChooserBlock(
        required=True,
        label=_('Parent page'),
        help_text=_(
            "Show a preview of pages that are children of the selected page. Uses ordering specified in the page’s LAYOUT tab."  # noqa
        ),
    )
    classified_by = ClassifierTermChooserBlock(
        required=False,
        label=_('Classified as'),
        help_text=_('Only show pages that are classified with this term.')
    )
    show_preview = blocks.BooleanBlock(
        required=False,
        default=False,
        label=_('Show body preview'),
    )
github mdn / developer-portal / developerportal / apps / home / migrations / 0011_auto_20190627_1528.py View on Github external
import wagtail.core.fields


class Migration(migrations.Migration):

    dependencies = [("home", "0010_auto_20190627_1527")]

    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",
                        wagtail.core.blocks.StructBlock(
                            [
                                ("title", wagtail.core.blocks.CharBlock()),
                                ("description", wagtail.core.blocks.TextBlock()),
                                ("url", wagtail.core.blocks.URLBlock()),
                            ]
                        ),
                    ),
                ],
                blank=True,
                null=True,
github thepoly / pipeline / home / migrations / 0004_homepage_featured_articles.py View on Github external
import wagtail.core.fields


class Migration(migrations.Migration):

    dependencies = [("home", "0003_homepage_featured_article")]

    operations = [
        migrations.AddField(
            model_name="homepage",
            name="featured_articles",
            field=wagtail.core.fields.StreamField(
                [
                    (
                        "article",
                        wagtail.core.blocks.PageChooserBlock(
                            target_model=["articles.ArticlePage"]
                        ),
                    )
                ],
                null=True,
            ),