From 89bb3787e3b0ed99210ff4bd23b34ec32720e537 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Mon, 9 Feb 2015 12:35:19 +0000 Subject: [PATCH] Improvements to #620 As per https://github.com/torchbox/wagtail/pull/620#issuecomment-59203932 Also improved the tests a little bit --- .../templatetags/wagtailcore_tags.py | 9 ++++++--- wagtail/wagtailcore/tests/tests.py | 17 ++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/wagtail/wagtailcore/templatetags/wagtailcore_tags.py b/wagtail/wagtailcore/templatetags/wagtailcore_tags.py index c3b660a16a..c0cf66e29b 100644 --- a/wagtail/wagtailcore/templatetags/wagtailcore_tags.py +++ b/wagtail/wagtailcore/templatetags/wagtailcore_tags.py @@ -35,6 +35,9 @@ def wagtail_version(): @register.filter def richtext(value): - if value: - return mark_safe('
' + expand_db_html(value) + '
') - return '' + if value is not None: + html = expand_db_html(value) + else: + html = '' + + return mark_safe('
' + html + '
') diff --git a/wagtail/wagtailcore/tests/tests.py b/wagtail/wagtailcore/tests/tests.py index 3531a35aeb..fd2e4de937 100644 --- a/wagtail/wagtailcore/tests/tests.py +++ b/wagtail/wagtailcore/tests/tests.py @@ -2,6 +2,7 @@ import unittest from django.test import TestCase from django.core.cache import cache +from django.utils.safestring import SafeString from wagtail.wagtailcore.models import Page, Site from wagtail.wagtailcore.templatetags.wagtailcore_tags import richtext @@ -188,13 +189,11 @@ class TestResolveModelString(TestCase): class TestRichtextTag(TestCase): + def test_call_with_text(self): + result = richtext("Hello world!") + self.assertEqual(result, '
Hello world!
') + self.assertIsInstance(result, SafeString) - def test_typeerror(self): - """`richtext` fails when it's called with `value` being not a string - or buffer. - """ - value = None - - result = richtext(value) - - self.assertEqual(result, '') + def test_call_with_none(self): + result = richtext(None) + self.assertEqual(result, '
')