fix: #1735 Unable to use models with a StreamField inside Inline Panels

pull/2856/head
Gagaro 2016-06-01 14:38:29 +02:00 zatwierdzone przez Matt Westcott
rodzic 7d8c7ec758
commit 16c279d705
7 zmienionych plików z 88 dodań i 0 usunięć

Wyświetl plik

@ -33,6 +33,7 @@ Changelog
* Fix: `RichText` values can now be correctly evaluated as booleans (Mike Dingjan, Bertrand Bordage)
* Fix: wagtailforms no longer assumes an .html extension when determining the landing page template filename (kakulukia)
* Fix: Fixed styling glitch on bi-colour icon + text buttons in Chrome (Janneke Janssen)
* Fix: StreamField can now be used in an InlinePanel (Gagaro)
1.5.3 (18.07.2016)
@ -46,6 +47,7 @@ Changelog
* Fixed regression in 1.5.1 on editing external links (Stephen Rice)
1.5.1 (07.06.2016)
~~~~~~~~~~~~~~~~~~

Wyświetl plik

@ -63,6 +63,7 @@ Bug fixes
* ``RichText`` values can now be correctly evaluated as booleans (Mike Dingjan, Bertrand Bordage)
* wagtailforms no longer assumes an .html extension when determining the landing page template filename (kakulukia)
* Fixed styling glitch on bi-colour icon + text buttons in Chrome (Janneke Janssen)
* StreamField can now be used in an InlinePanel (Gagaro)
Upgrade considerations

Wyświetl plik

@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.8 on 2016-07-19 15:47
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
import modelcluster.fields
import wagtail.wagtailcore.blocks
import wagtail.wagtailcore.fields
import wagtail.wagtailimages.blocks
class Migration(migrations.Migration):
dependencies = [
('wagtailcore', '0029_unicode_slugfield_dj19'),
('tests', '0007_jadeformpage'),
]
operations = [
migrations.CreateModel(
name='InlineStreamPage',
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')),
],
options={
'abstract': False,
},
bases=('wagtailcore.page',),
),
migrations.CreateModel(
name='InlineStreamPageSection',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('sort_order', models.IntegerField(blank=True, editable=False, null=True)),
('body', wagtail.wagtailcore.fields.StreamField((('text', wagtail.wagtailcore.blocks.CharBlock()), ('rich_text', wagtail.wagtailcore.blocks.RichTextBlock()), ('image', wagtail.wagtailimages.blocks.ImageChooserBlock())))),
('page', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='sections', to='tests.InlineStreamPage')),
],
options={
'abstract': False,
'ordering': ['sort_order'],
},
),
]

Wyświetl plik

@ -753,3 +753,22 @@ class SectionedRichTextPage(Page):
FieldPanel('title', classname="full title"),
InlinePanel('sections')
]
class InlineStreamPageSection(Orderable):
page = ParentalKey('tests.InlineStreamPage', related_name='sections', on_delete=models.CASCADE)
body = StreamField([
('text', CharBlock()),
('rich_text', RichTextBlock()),
('image', ImageChooserBlock()),
])
panels = [
StreamFieldPanel('body')
]
class InlineStreamPage(Page):
content_panels = [
FieldPanel('title', classname="full title"),
InlinePanel('sections')
]

Wyświetl plik

@ -621,6 +621,10 @@ class BaseInlinePanel(EditHandler):
}
}
@classmethod
def html_declarations(cls):
return cls.get_child_edit_handler_class().html_declarations()
def __init__(self, instance=None, form=None):
super(BaseInlinePanel, self).__init__(instance=instance, form=form)

Wyświetl plik

@ -3044,3 +3044,18 @@ class TestInlinePanelMedia(TestCase, WagtailTestUtils):
response = self.client.get(reverse('wagtailadmin_pages:add', args=('tests', 'sectionedrichtextpage', homepage.id)))
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'wagtailadmin/js/hallo-bootstrap.js')
class TestInlineStreamField(TestCase, WagtailTestUtils):
"""
Test that streamfields inside an inline child work
"""
def test_inline_streamfield(self):
homepage = Page.objects.get(id=2)
self.login()
response = self.client.get(reverse('wagtailadmin_pages:add', args=('tests', 'inlinestreampage', homepage.id)))
self.assertEqual(response.status_code, 200)
# response should include HTML declarations for streamfield child blocks
self.assertContains(response, '<li id="__PREFIX__-container" class="sequence-member blockname-rich_text">')

Wyświetl plik

@ -125,6 +125,9 @@ class BaseStreamBlock(Block):
raise TypeError('StreamBlock.render_form unexpectedly received multiple errors')
error_dict = errors.as_data()[0].params
# value can be None when the StreamField is in a formset
if value is None:
value = self.get_default()
# drop any child values that are an unrecognised block type
valid_children = [child for child in value if child.block_type in self.child_blocks]