kopia lustrzana https://github.com/wagtail/wagtail
Improvements to #620
As per https://github.com/torchbox/wagtail/pull/620#issuecomment-59203932 Also improved the tests a little bitpull/733/merge
rodzic
357a5c7449
commit
89bb3787e3
|
@ -35,6 +35,9 @@ def wagtail_version():
|
|||
|
||||
@register.filter
|
||||
def richtext(value):
|
||||
if value:
|
||||
return mark_safe('<div class="rich-text">' + expand_db_html(value) + '</div>')
|
||||
return ''
|
||||
if value is not None:
|
||||
html = expand_db_html(value)
|
||||
else:
|
||||
html = ''
|
||||
|
||||
return mark_safe('<div class="rich-text">' + html + '</div>')
|
||||
|
|
|
@ -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, '<div class="rich-text">Hello world!</div>')
|
||||
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, '<div class="rich-text"></div>')
|
||||
|
|
Ładowanie…
Reference in New Issue