{"action":"created","issue":{"url":"https://api.github.com/repos/torchbox/wagtail/issues/2336","repository_url":"https://api.github.com/repos/torchbox/wagtail","labels_url":"https://api.github.com/repos/torchbox/wagtail/issues/2336/labels{/name}","comments_url":"https://api.github.com/repos/torchbox/wagtail/issues/2336/comments","events_url":"https://api.github.com/repos/torchbox/wagtail/issues/2336/events","html_url":"https://github.com/torchbox/wagtail/issues/2336","id":139950785,"number":2336,"title":"Unable to check whether a RichTextBlock is empty","user":{"login":"BertrandBordage","id":1119169,"avatar_url":"https://avatars.githubusercontent.com/u/1119169?v=3","gravatar_id":"","url":"https://api.github.com/users/BertrandBordage","html_url":"https://github.com/BertrandBordage","followers_url":"https://api.github.com/users/BertrandBordage/followers","following_url":"https://api.github.com/users/BertrandBordage/following{/other_user}","gists_url":"https://api.github.com/users/BertrandBordage/gists{/gist_id}","starred_url":"https://api.github.com/users/BertrandBordage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BertrandBordage/subscriptions","organizations_url":"https://api.github.com/users/BertrandBordage/orgs","repos_url":"https://api.github.com/users/BertrandBordage/repos","events_url":"https://api.github.com/users/BertrandBordage/events{/privacy}","received_events_url":"https://api.github.com/users/BertrandBordage/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/torchbox/wagtail/labels/Ready%20to%20develop!","name":"Ready to develop!","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-03-10T16:59:35Z","updated_at":"2016-03-10T21:51:38Z","closed_at":null,"body":"When you use `RichTextBlock` in a template – especially when it’s in a `StructBlock` – you sometimes need to do something like this:\r\n```html+django\r\n{% if value.description %}\r\n  <div class=\"something\">\r\n    {{ value.description }}\r\n  </div>\r\n{% endif %}\r\n```\r\nHowever, the test always evaluates to `True` because `value.description` is a `RichText` object that only implements a `__str__` method. This `__str__` always returns at least `'<div class=\"rich-text\"></div>'`.\r\n\r\nThe solution is to add a `__bool__` method like this:\r\n```python\r\n    def __bool__(self):\r\n        return bool(self.source)\r\n```\r\nAnother solution may consist in adding this `<div class=\"rich-text\"></div>` only if the block is not empty."},"comment":{"url":"https://api.github.com/repos/torchbox/wagtail/issues/comments/195067247","html_url":"https://github.com/torchbox/wagtail/issues/2336#issuecomment-195067247","issue_url":"https://api.github.com/repos/torchbox/wagtail/issues/2336","id":195067247,"user":{"login":"BertrandBordage","id":1119169,"avatar_url":"https://avatars.githubusercontent.com/u/1119169?v=3","gravatar_id":"","url":"https://api.github.com/users/BertrandBordage","html_url":"https://github.com/BertrandBordage","followers_url":"https://api.github.com/users/BertrandBordage/followers","following_url":"https://api.github.com/users/BertrandBordage/following{/other_user}","gists_url":"https://api.github.com/users/BertrandBordage/gists{/gist_id}","starred_url":"https://api.github.com/users/BertrandBordage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BertrandBordage/subscriptions","organizations_url":"https://api.github.com/users/BertrandBordage/orgs","repos_url":"https://api.github.com/users/BertrandBordage/repos","events_url":"https://api.github.com/users/BertrandBordage/events{/privacy}","received_events_url":"https://api.github.com/users/BertrandBordage/received_events","type":"User","site_admin":false},"created_at":"2016-03-10T21:51:38Z","updated_at":"2016-03-10T21:51:38Z","body":"From what I saw in the current release (1.4rc1), saving an empty `RichTextBlock` always returns an empty string, but I know I saw the `<p></p>` issue on `RichTextField` in the past. The solution would be to clean the field as I did in my projects, but we of course need to make this robust and handle similar cases like `<p><em></em></p>`, `<p> </p>`, `<p>[any space here, non-breaking, narrow non breaking, etc]</p>`."}}