Beispiel #1
0
class ResourcesPage(Page):
    resources = StreamField(
        [
            (
                "resource",
                blocks.StreamBlock(
                    [
                        ("resource_name", blocks.CharBlock()),
                        ("information", blocks.RichTextBlock()),
                        (
                            "structured_info_block",
                            blocks.StreamBlock(
                                [
                                    ("heading", blocks.CharBlock()),
                                    ("body", blocks.RichTextBlock()),
                                ]
                            ),
                        ),
                    ]
                ),
            )
        ],
        use_json_field=True,
    )
    content_panels = Page.content_panels + [
        FieldPanel("resources"),
    ]
Beispiel #2
0
class DocumentPage(Page):
    date_published = models.DateField("Last Updated", blank=True, null=True)
    body = StreamField(
        [(
            "section",
            blocks.StreamBlock([
                ("header", CharBlock()),
                ("text", blocks.RichTextBlock()),
                ("quote", BlockQuoteBlock()),
                (
                    "subsection",
                    blocks.StreamBlock([
                        ("header", CharBlock()),
                        ("text", blocks.TextBlock()),
                        (
                            "subsubsection",
                            blocks.StreamBlock([
                                ("header", CharBlock()),
                                ("text", blocks.TextBlock()),
                            ]),
                        ),
                    ]),
                ),
            ]),
        )],
        null=True,
        blank=True,
        use_json_field=True,
    )

    content_panels = Page.content_panels + [
        FieldPanel("date_published"),
        FieldPanel("body"),
    ]
Beispiel #3
0
    def test_rich_text_is_safe(self):
        """
        Ensure that RichText values are marked safe
        so that they don't get double-escaped when inserted into a parent template (#2542)
        """
        stream_block = blocks.StreamBlock([(
            "paragraph",
            blocks.RichTextBlock(template="tests/jinja2/rich_text.html"),
        )])
        stream_value = stream_block.to_python([
            {
                "type": "paragraph",
                "value":
                '<p>Merry <a linktype="page" id="4">Christmas</a>!</p>',
            },
        ])

        result = render_to_string(
            "tests/jinja2/stream.html",
            {
                "value": stream_value,
            },
        )

        self.assertIn(
            '<p>Merry <a href="/events/christmas/">Christmas</a>!</p>', result)
Beispiel #4
0
 class DeprecatedStreamModel(models.Model):
     body = StreamField(
         [
             ("heading", blocks.CharBlock()),
             ("rich text", blocks.RichTextBlock()),
         ],
     )
Beispiel #5
0
class SectionBlock(blocks.StructBlock):
    title = blocks.CharBlock()
    body = blocks.RichTextBlock()

    class Meta:
        icon = "form"
        template = "tests/blocks/section_block.html"
Beispiel #6
0
        class TestStreamBlock(blocks.StreamBlock):
            heading = blocks.CharBlock()
            paragraph = blocks.RichTextBlock()

            class Meta:
                min_num = 2
                max_num = 5
                block_counts = {"heading": {"max_num": 1}}
Beispiel #7
0
 class InvalidStreamModel(models.Model):
     body = StreamField(
         [
             ("heading", blocks.CharBlock()),
             ("rich text", blocks.RichTextBlock()),
         ],
         use_json_field=self.use_json_field,
     )
Beispiel #8
0
class MapBlock(blocks.StructBlock):
    marker_title = blocks.CharBlock(max_length=120,
                                    default="Marker Title 'This will be updated after you save changes.'")
    marker_description = blocks.RichTextBlock()
    zoom_level = blocks.IntegerBlock(min_value=0, max_value=18, default='2', required=False)
    location_x = blocks.FloatBlock(default='35.0', required=False)
    location_y = blocks.FloatBlock(default='0.16', required=False)
    marker_x = blocks.FloatBlock(default='51.5', required=False)
    marker_y = blocks.FloatBlock(default='-0.09', required=False)

    @property
    def media(self):
        return forms.Media(
            js=["https://unpkg.com/[email protected]/dist/leaflet.js"],
            css={'all': ["https://unpkg.com/[email protected]/dist/leaflet.css"]}
        )

    class Meta:
        form_template = 'wagtail_blocks/admin_blocks/map.html'
        template = 'wagtail_blocks/map.html'
        icon = "fa-globe"
Beispiel #9
0
class Migration(migrations.Migration):

    dependencies = [
        ('tests', '0012_pagewithrelatedpages'),
    ]

    operations = [
        migrations.AlterField(
            model_name='pagewithstreamfield',
            name='body',
            field=wagtail_fields.StreamField([('link_block', wagtail_blocks.StructBlock([('page', wagtail_blocks.PageChooserBlock(required=False)), ('text', wagtail_blocks.CharBlock(max_length=250))])), ('page', wagtail_blocks.PageChooserBlock()), ('stream', wagtail_blocks.StreamBlock([('page', wagtail_blocks.PageChooserBlock())])), ('rich_text', wagtail_blocks.RichTextBlock()), ('list_of_pages', wagtail_blocks.ListBlock(wagtail_blocks.PageChooserBlock()))], blank=True, verbose_name='Page body'),
        ),
    ]
class Migration(migrations.Migration):

    dependencies = [
        ('wagtailcore', '0041_group_collection_permissions_verbose_name_plural'),
        ('tests', '0004_pagewithrichtext'),
    ]

    operations = [
        migrations.CreateModel(
            name='PageWithStreamField',
            fields=[
                ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
                ('body', wagtail_fields.StreamField([('link_block', wagtail_blocks.StructBlock([('page', wagtail_blocks.PageChooserBlock()), ('text', wagtail_blocks.CharBlock(max_length=250))])), ('page', wagtail_blocks.PageChooserBlock()), ('stream', wagtail_blocks.StreamBlock([('page', wagtail_blocks.PageChooserBlock())])), ('rich_text', wagtail_blocks.RichTextBlock()), ('list_of_pages', wagtail_blocks.ListBlock(wagtail_blocks.PageChooserBlock()))], blank=True, verbose_name='Page body')),
            ],
            options={
                'abstract': False,
            },
            bases=('wagtailcore.page',),
        ),
    ]