Added __bool__ method for proper evaluating the RichText object value

pull/2762/merge
Mike Dingjan 2016-06-16 15:40:42 +02:00 zatwierdzone przez Matt Westcott
rodzic 6ae36c0baa
commit 33f53a6e78
5 zmienionych plików z 14 dodań i 0 usunięć

Wyświetl plik

@ -19,6 +19,7 @@ Changelog
* Fix: Fixed incorrect CSS path on ModelAdmin's "choose a parent page" view
* Fix: Prevent empty redirect by overnormalisation (Franklin Kingma, Ludolf Takens)
* Fix: "Remove link" button in rich text editor didn't trigger "edit" event, leading to the change to sometimes not be persisted (Matt Westcott)
* Fix: `RichText` values can now be correctly evaluated as booleans (Mike Dingjan, Bertrand Bordage)
1.5.2 (08.06.2016)

Wyświetl plik

@ -146,6 +146,7 @@ Contributors
* Franklin Kingma
* Ludolf Takens
* Oktay Altay
* Bertrand Bordage
Translators
===========

Wyświetl plik

@ -34,6 +34,7 @@ Bug fixes
* Fixed incorrect CSS path on ModelAdmin's "choose a parent page" view
* Prevent empty redirect by overnormalisation
* "Remove link" button in rich text editor didn't trigger "edit" event, leading to the change to sometimes not be persisted (Matt Westcott)
* ``RichText`` values can now be correctly evaluated as booleans (Mike Dingjan, Bertrand Bordage)
Upgrade considerations

Wyświetl plik

@ -195,3 +195,7 @@ class RichText(object):
def __str__(self):
return mark_safe('<div class="rich-text">' + expand_db_html(self.source) + '</div>')
def __bool__(self):
return bool(self.source)
__nonzero__ = __bool__

Wyświetl plik

@ -145,3 +145,10 @@ class TestRichTextValue(TestCase):
result,
'<div class="rich-text"><p>Merry <a href="/events/christmas/">Christmas</a>!</p></div>'
)
def test_evaluate_value(self):
value = RichText(None)
self.assertFalse(value)
value = RichText('<p>wagtail</p>')
self.assertTrue(value)