kopia lustrzana https://github.com/wagtail/wagtail
Add missing condition for StreamBlockComparison
rodzic
55d82d6167
commit
3d7f2d0905
|
@ -17,6 +17,7 @@ Changelog
|
|||
* Fix: `WAGTAILFRONTENDCACHE_LANGUAGES` was being interpreted incorrectly. It now accepts a list of strings, as documented (Karl Hobley)
|
||||
* Fix: Update oEmbed endpoints to use https where available (Matt Westcott)
|
||||
* Fix: Revise `edit_handler` bind order in ModelAdmin views and fix duplicate form instance creation (Jérôme Lebleu)
|
||||
* Fix: Properly distinguish child blocks when comparing revisions with nested StreamBlocks (Martin Mena)
|
||||
|
||||
|
||||
2.10.2 (xx.xx.xxxx) - IN DEVELOPMENT
|
||||
|
|
|
@ -31,6 +31,7 @@ Bug fixes
|
|||
* ``WAGTAILFRONTENDCACHE_LANGUAGES`` was being interpreted incorrectly. It now accepts a list of strings, as documented (Karl Hobley)
|
||||
* Update oEmbed endpoints to use https where available (Matt Westcott)
|
||||
* Revise ``edit_handler`` bind order in ModelAdmin views and fix duplicate form instance creation (Jérôme Lebleu)
|
||||
* Properly distinguish child blocks when comparing revisions with nested StreamBlocks (Martin Mena)
|
||||
|
||||
|
||||
Upgrade considerations
|
||||
|
|
|
@ -74,6 +74,8 @@ def get_comparison_class_for_block(block):
|
|||
return RichTextBlockComparison
|
||||
elif isinstance(block, blocks.StructBlock):
|
||||
return StructBlockComparison
|
||||
elif isinstance(block, blocks.StreamBlock):
|
||||
return StreamBlockComparison
|
||||
else:
|
||||
# As all stream field blocks have a HTML representation, fall back to diffing that.
|
||||
return RichTextBlockComparison
|
||||
|
|
|
@ -419,6 +419,28 @@ class TestStreamFieldComparison(TestCase):
|
|||
self.assertIsInstance(comparison.htmldiff(), SafeString)
|
||||
self.assertTrue(comparison.has_changed())
|
||||
|
||||
def test_compare_nested_streamblock_uses_comparison_class(self):
|
||||
field = StreamPage._meta.get_field('body')
|
||||
stream_block = field.stream_block.child_blocks['books']
|
||||
comparison = self.comparison_class(
|
||||
field,
|
||||
StreamPage(body=StreamValue(field.stream_block, [
|
||||
('books', StreamValue(stream_block, [('title', 'The Old Man and the Sea', '10')]), '1'),
|
||||
])),
|
||||
StreamPage(body=StreamValue(field.stream_block, [
|
||||
('books', StreamValue(stream_block, [('author', 'Oscar Wilde', '11')]), '1'),
|
||||
])),
|
||||
)
|
||||
expected = """
|
||||
<div class="comparison__child-object">
|
||||
<div class="comparison__child-object addition">Oscar Wilde</div>\n
|
||||
<div class="comparison__child-object deletion">The Old Man and the Sea</div>
|
||||
</div>
|
||||
"""
|
||||
self.assertHTMLEqual(comparison.htmldiff(), expected)
|
||||
self.assertIsInstance(comparison.htmldiff(), SafeString)
|
||||
self.assertTrue(comparison.has_changed())
|
||||
|
||||
def test_compare_imagechooserblock(self):
|
||||
image_model = get_image_model()
|
||||
test_image_1 = image_model.objects.create(
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
# Generated by Django 3.0.9 on 2020-08-12 20:27
|
||||
|
||||
from django.db import migrations
|
||||
import wagtail.core.blocks
|
||||
import wagtail.core.fields
|
||||
import wagtail.tests.testapp.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('tests', '0055_eventpage_childobject_i18n'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='streampage',
|
||||
name='body',
|
||||
field=wagtail.core.fields.StreamField([('text', wagtail.core.blocks.CharBlock()), ('rich_text', wagtail.core.blocks.RichTextBlock()), ('image', wagtail.tests.testapp.models.ExtendedImageChooserBlock()), ('product', wagtail.core.blocks.StructBlock([('name', wagtail.core.blocks.CharBlock()), ('price', wagtail.core.blocks.CharBlock())])), ('raw_html', wagtail.core.blocks.RawHTMLBlock()), ('books', wagtail.core.blocks.StreamBlock([('title', wagtail.core.blocks.CharBlock()), ('author', wagtail.core.blocks.CharBlock())]))]),
|
||||
),
|
||||
]
|
|
@ -31,7 +31,7 @@ from wagtail.contrib.forms.views import SubmissionsListView
|
|||
from wagtail.contrib.settings.models import BaseSetting, register_setting
|
||||
from wagtail.contrib.sitemaps import Sitemap
|
||||
from wagtail.contrib.table_block.blocks import TableBlock
|
||||
from wagtail.core.blocks import CharBlock, RawHTMLBlock, RichTextBlock, StructBlock
|
||||
from wagtail.core.blocks import CharBlock, RawHTMLBlock, RichTextBlock, StreamBlock, StructBlock
|
||||
from wagtail.core.fields import RichTextField, StreamField
|
||||
from wagtail.core.models import Orderable, Page, PageManager, PageQuerySet, Task, TranslatableMixin
|
||||
from wagtail.documents.edit_handlers import DocumentChooserPanel
|
||||
|
@ -1024,6 +1024,10 @@ class StreamPage(Page):
|
|||
('price', CharBlock()),
|
||||
])),
|
||||
('raw_html', RawHTMLBlock()),
|
||||
('books', StreamBlock([
|
||||
('title', CharBlock()),
|
||||
('author', CharBlock()),
|
||||
])),
|
||||
])
|
||||
|
||||
api_fields = ('body',)
|
||||
|
|
Ładowanie…
Reference in New Issue