diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 362dcc9e1f..e43e850f12 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -13,6 +13,7 @@ Changelog * Fix: Remove comment button on InlinePanel fields (Sage Abdullah) * Fix: Fix missing link to `UsageView` from `EditView` for snippets (Christer Jensen) * Fix: Prevent lowercase conversions of IndexView column headers (Virag Jain) + * Fix: Ensure that `RichText` objects with the same values compare as equal (NikilTn) * Docs: Document how to add non-ModelAdmin views to a `ModelAdminGroup` (Onno Timmerman) * Docs: Document how to add StructBlock data to a StreamField (Ramon Wenger) * Docs: Update ReadTheDocs settings to v2 to resolve urllib3 issue in linkcheck extension (Thibaud Colas) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 344e6af2c8..814f7082f7 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -715,6 +715,7 @@ Contributors * Lukas von Allmen * Ester Beltrami * Justin Koestinger +* NikilTn Translators =========== diff --git a/docs/releases/5.1.md b/docs/releases/5.1.md index 0a7e07c518..41b1720062 100644 --- a/docs/releases/5.1.md +++ b/docs/releases/5.1.md @@ -28,6 +28,7 @@ FieldPanels can now be marked as read-only with the `read_only=True` keyword arg * Remove comment button on InlinePanel fields (Sage Abdullah) * Fix missing link to `UsageView` from `EditView` for snippets (Christer Jensen) * Prevent lowercase conversions of IndexView column headers (Virag Jain) + * Ensure that `RichText` objects with the same values compare as equal (NikilTn) ### Documentation diff --git a/wagtail/rich_text/__init__.py b/wagtail/rich_text/__init__.py index 51494e1a8a..aee09cb784 100644 --- a/wagtail/rich_text/__init__.py +++ b/wagtail/rich_text/__init__.py @@ -99,6 +99,11 @@ class RichText: def __bool__(self): return bool(self.source) + def __eq__(self, other): + if isinstance(other, RichText): + return self.source == other.source + return False + class EntityHandler: """ diff --git a/wagtail/tests/test_rich_text.py b/wagtail/tests/test_rich_text.py index 7467e5d406..0bc3b95b71 100644 --- a/wagtail/tests/test_rich_text.py +++ b/wagtail/tests/test_rich_text.py @@ -131,6 +131,14 @@ class TestRichTextValue(TestCase): value = RichText("

wagtail

") self.assertTrue(value) + def test_compare_value(self): + value1 = RichText("

wagtail

") + value2 = RichText("

wagtail

") + value3 = RichText("

django

") + self.assertNotEqual(value1, value3) + self.assertNotEqual(value1, 12345) + self.assertEqual(value1, value2) + class TestFeatureRegistry(TestCase): def test_register_rich_text_features_hook(self):