added __eq__ for comparison of the source of RichText and also added compare test case

Fixes #10523
pull/10542/head
NikilTn 2023-06-09 14:18:01 +05:30 zatwierdzone przez Matt Westcott
rodzic bd76b020af
commit 7b3b55ff93
5 zmienionych plików z 16 dodań i 0 usunięć

Wyświetl plik

@ -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)

Wyświetl plik

@ -715,6 +715,7 @@ Contributors
* Lukas von Allmen
* Ester Beltrami
* Justin Koestinger
* NikilTn
Translators
===========

Wyświetl plik

@ -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

Wyświetl plik

@ -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:
"""

Wyświetl plik

@ -131,6 +131,14 @@ class TestRichTextValue(TestCase):
value = RichText("<p>wagtail</p>")
self.assertTrue(value)
def test_compare_value(self):
value1 = RichText("<p>wagtail</p>")
value2 = RichText("<p>wagtail</p>")
value3 = RichText("<p>django</p>")
self.assertNotEqual(value1, value3)
self.assertNotEqual(value1, 12345)
self.assertEqual(value1, value2)
class TestFeatureRegistry(TestCase):
def test_register_rich_text_features_hook(self):