本文整理匯總了Python中django.utils.safestring.SafeString方法的典型用法代碼示例。如果您正苦於以下問題:Python safestring.SafeString方法的具體用法?Python safestring.SafeString怎麽用?Python safestring.SafeString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.utils.safestring
的用法示例。
在下文中一共展示了safestring.SafeString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_hasnt_changed
# 需要導入模塊: from django.utils import safestring [as 別名]
# 或者: from django.utils.safestring import SafeString [as 別名]
def test_hasnt_changed(self):
field = StreamPage._meta.get_field('body')
comparison = self.comparison_class(
field,
StreamPage(body=StreamValue(field.stream_block, [
('text', "Content", '1'),
])),
StreamPage(body=StreamValue(field.stream_block, [
('text', "Content", '1'),
])),
)
self.assertTrue(comparison.is_field)
self.assertFalse(comparison.is_child_relation)
self.assertEqual(comparison.field_label(), "Body")
self.assertEqual(comparison.htmldiff(), '<div class="comparison__child-object">Content</div>')
self.assertIsInstance(comparison.htmldiff(), SafeString)
self.assertFalse(comparison.has_changed())
示例2: test_has_changed
# 需要導入模塊: from django.utils import safestring [as 別名]
# 或者: from django.utils.safestring import SafeString [as 別名]
def test_has_changed(self):
field = StreamPage._meta.get_field('body')
comparison = self.comparison_class(
field,
StreamPage(body=StreamValue(field.stream_block, [
('text', "Original content", '1'),
])),
StreamPage(body=StreamValue(field.stream_block, [
('text', "Modified content", '1'),
])),
)
self.assertEqual(comparison.htmldiff(), '<div class="comparison__child-object"><span class="deletion">Original</span><span class="addition">Modified</span> content</div>')
self.assertIsInstance(comparison.htmldiff(), SafeString)
self.assertTrue(comparison.has_changed())
示例3: test_delete_block
# 需要導入模塊: from django.utils import safestring [as 別名]
# 或者: from django.utils.safestring import SafeString [as 別名]
def test_delete_block(self):
field = StreamPage._meta.get_field('body')
comparison = self.comparison_class(
field,
StreamPage(body=StreamValue(field.stream_block, [
('text', "Content", '1'),
('text', "Content Foo", '2'),
('text', "Content Bar", '3'),
])),
StreamPage(body=StreamValue(field.stream_block, [
('text', "Content", '1'),
('text', "Content Bar", '3'),
])),
)
self.assertEqual(comparison.htmldiff(), '<div class="comparison__child-object">Content</div>\n<div class="comparison__child-object deletion">Content Foo</div>\n<div class="comparison__child-object">Content Bar</div>')
self.assertIsInstance(comparison.htmldiff(), SafeString)
self.assertTrue(comparison.has_changed())
示例4: test_edit_block
# 需要導入模塊: from django.utils import safestring [as 別名]
# 或者: from django.utils.safestring import SafeString [as 別名]
def test_edit_block(self):
field = StreamPage._meta.get_field('body')
comparison = self.comparison_class(
field,
StreamPage(body=StreamValue(field.stream_block, [
('text', "Content", '1'),
('text', "Content Foo", '2'),
('text', "Content Bar", '3'),
])),
StreamPage(body=StreamValue(field.stream_block, [
('text', "Content", '1'),
('text', "Content Baz", '2'),
('text', "Content Bar", '3'),
])),
)
self.assertEqual(comparison.htmldiff(), '<div class="comparison__child-object">Content</div>\n<div class="comparison__child-object">Content <span class="deletion">Foo</span><span class="addition">Baz</span></div>\n<div class="comparison__child-object">Content Bar</div>')
self.assertIsInstance(comparison.htmldiff(), SafeString)
self.assertTrue(comparison.has_changed())
示例5: test_has_changed_richtext
# 需要導入模塊: from django.utils import safestring [as 別名]
# 或者: from django.utils.safestring import SafeString [as 別名]
def test_has_changed_richtext(self):
field = StreamPage._meta.get_field('body')
comparison = self.comparison_class(
field,
StreamPage(body=StreamValue(field.stream_block, [
('rich_text', "<b>Original</b> content", '1'),
])),
StreamPage(body=StreamValue(field.stream_block, [
('rich_text', "Modified <i>content</i>", '1'),
])),
)
self.assertEqual(comparison.htmldiff(), '<div class="comparison__child-object"><span class="deletion">Original</span><span class="addition">Modified</span> content</div>')
self.assertIsInstance(comparison.htmldiff(), SafeString)
self.assertTrue(comparison.has_changed())
示例6: test_htmldiff_escapes_value_on_addition
# 需要導入模塊: from django.utils import safestring [as 別名]
# 或者: from django.utils.safestring import SafeString [as 別名]
def test_htmldiff_escapes_value_on_addition(self):
field = StreamPage._meta.get_field('body')
comparison = self.comparison_class(
field,
StreamPage(body=StreamValue(field.stream_block, [
('text', "Original <em>and unchanged</em> content", '1'),
])),
StreamPage(body=StreamValue(field.stream_block, [
('text', "Original <em>and unchanged</em> content", '1'),
('text', '<script type="text/javascript">doSomethingBad();</script>', '2'),
])),
)
self.assertEqual(comparison.htmldiff(), '<div class="comparison__child-object">Original <em>and unchanged</em> content</div>\n<div class="comparison__child-object addition"><script type="text/javascript">doSomethingBad();</script></div>')
self.assertIsInstance(comparison.htmldiff(), SafeString)
示例7: test_htmldiff_richtext_strips_tags_on_addition
# 需要導入模塊: from django.utils import safestring [as 別名]
# 或者: from django.utils.safestring import SafeString [as 別名]
def test_htmldiff_richtext_strips_tags_on_addition(self):
field = StreamPage._meta.get_field('body')
comparison = self.comparison_class(
field,
StreamPage(body=StreamValue(field.stream_block, [
('rich_text', "Original <em>and unchanged</em> content", '1'),
])),
StreamPage(body=StreamValue(field.stream_block, [
('rich_text', "Original <em>and unchanged</em> content", '1'),
('rich_text', 'I <b>really</b> like evil code >_< <script type="text/javascript">doSomethingBad();</script>', '2'),
])),
)
self.assertEqual(comparison.htmldiff(), '<div class="comparison__child-object">Original and unchanged content</div>\n<div class="comparison__child-object addition">I really like evil code >_< doSomethingBad();</div>')
self.assertIsInstance(comparison.htmldiff(), SafeString)
示例8: test_htmldiff_richtext_strips_tags_on_deletion
# 需要導入模塊: from django.utils import safestring [as 別名]
# 或者: from django.utils.safestring import SafeString [as 別名]
def test_htmldiff_richtext_strips_tags_on_deletion(self):
field = StreamPage._meta.get_field('body')
comparison = self.comparison_class(
field,
StreamPage(body=StreamValue(field.stream_block, [
('rich_text', "Original <em>and unchanged</em> content", '1'),
('rich_text', 'I <b>really</b> like evil code >_< <script type="text/javascript">doSomethingBad();</script>', '2'),
])),
StreamPage(body=StreamValue(field.stream_block, [
('rich_text', "Original <em>and unchanged</em> content", '1'),
])),
)
self.assertEqual(comparison.htmldiff(), '<div class="comparison__child-object">Original and unchanged content</div>\n<div class="comparison__child-object deletion">I really like evil code >_< doSomethingBad();</div>')
self.assertIsInstance(comparison.htmldiff(), SafeString)
示例9: test_compare_structblock
# 需要導入模塊: from django.utils import safestring [as 別名]
# 或者: from django.utils.safestring import SafeString [as 別名]
def test_compare_structblock(self):
field = StreamPage._meta.get_field('body')
comparison = self.comparison_class(
field,
StreamPage(body=StreamValue(field.stream_block, [
('product', {'name': 'a packet of rolos', 'price': '75p'}, '1'),
])),
StreamPage(body=StreamValue(field.stream_block, [
('product', {'name': 'a packet of rolos', 'price': '85p'}, '1'),
])),
)
expected = """
<div class="comparison__child-object"><dl>
<dt>Name</dt>
<dd>a packet of rolos</dd>
<dt>Price</dt>
<dd><span class="deletion">75p</span><span class="addition">85p</span></dd>
</dl></div>
"""
self.assertHTMLEqual(comparison.htmldiff(), expected)
self.assertIsInstance(comparison.htmldiff(), SafeString)
self.assertTrue(comparison.has_changed())
示例10: _cursor
# 需要導入模塊: from django.utils import safestring [as 別名]
# 或者: from django.utils.safestring import SafeString [as 別名]
def _cursor(self):
if not self._valid_connection():
kwargs = {'conv': base.django_conversions, 'dsn': None}
settings_dict = self.settings_dict
settings_dict.update(settings_dict.get('OPTIONS', {}))
for settings_key, kwarg, required in _SETTINGS_CONNECT_ARGS:
value = settings_dict.get(settings_key)
if value:
kwargs[kwarg] = value
elif required:
raise exceptions.ImproperlyConfigured(
"You must specify a '%s' for database '%s'" %
(settings_key, self.alias))
self.connection = Connect(**kwargs)
encoders = {safestring.SafeUnicode: self.connection.encoders[unicode],
safestring.SafeString: self.connection.encoders[str]}
self.connection.encoders.update(encoders)
signals.connection_created.send(sender=self.__class__, connection=self)
cursor = base.CursorWrapper(self.connection.cursor())
return cursor
示例11: test_htmldiff_escapes_value
# 需要導入模塊: from django.utils import safestring [as 別名]
# 或者: from django.utils.safestring import SafeString [as 別名]
def test_htmldiff_escapes_value(self):
comparison = self.comparison_class(
SimplePage._meta.get_field('content'),
SimplePage(content='Original content'),
SimplePage(content='<script type="text/javascript">doSomethingBad();</script>'),
)
self.assertEqual(comparison.htmldiff(), '<span class="deletion">Original content</span><span class="addition"><script type="text/javascript">doSomethingBad();</script></span>')
self.assertIsInstance(comparison.htmldiff(), SafeString)
示例12: test_from_none_to_value_only_shows_addition
# 需要導入模塊: from django.utils import safestring [as 別名]
# 或者: from django.utils.safestring import SafeString [as 別名]
def test_from_none_to_value_only_shows_addition(self):
comparison = self.comparison_class(
SimplePage._meta.get_field('content'),
SimplePage(content=None),
SimplePage(content="Added content")
)
self.assertEqual(comparison.htmldiff(), '<span class="addition">Added content</span>')
self.assertIsInstance(comparison.htmldiff(), SafeString)
self.assertTrue(comparison.has_changed())
示例13: test_has_changed_html
# 需要導入模塊: from django.utils import safestring [as 別名]
# 或者: from django.utils.safestring import SafeString [as 別名]
def test_has_changed_html(self):
comparison = self.comparison_class(
SimplePage._meta.get_field('content'),
SimplePage(content="<b>Original</b> content"),
SimplePage(content="Modified <i>content</i>"),
)
self.assertEqual(comparison.htmldiff(), '<span class="deletion">Original</span><span class="addition">Modified</span> content')
self.assertIsInstance(comparison.htmldiff(), SafeString)
self.assertTrue(comparison.has_changed())
示例14: test_htmldiff_escapes_value_on_change
# 需要導入模塊: from django.utils import safestring [as 別名]
# 或者: from django.utils.safestring import SafeString [as 別名]
def test_htmldiff_escapes_value_on_change(self):
field = StreamPage._meta.get_field('body')
comparison = self.comparison_class(
field,
StreamPage(body=StreamValue(field.stream_block, [
('text', "I <b>really</b> like original<i>ish</i> content", '1'),
])),
StreamPage(body=StreamValue(field.stream_block, [
('text', 'I <b>really</b> like evil code <script type="text/javascript">doSomethingBad();</script>', '1'),
])),
)
self.assertEqual(comparison.htmldiff(), '<div class="comparison__child-object">I <b>really</b> like <span class="deletion">original<i>ish</i> content</span><span class="addition">evil code <script type="text/javascript">doSomethingBad();</script></span></div>')
self.assertIsInstance(comparison.htmldiff(), SafeString)
示例15: test_htmldiff_richtext_strips_tags_on_change
# 需要導入模塊: from django.utils import safestring [as 別名]
# 或者: from django.utils.safestring import SafeString [as 別名]
def test_htmldiff_richtext_strips_tags_on_change(self):
field = StreamPage._meta.get_field('body')
comparison = self.comparison_class(
field,
StreamPage(body=StreamValue(field.stream_block, [
('rich_text', "I <b>really</b> like Wagtail <3", '1'),
])),
StreamPage(body=StreamValue(field.stream_block, [
('rich_text', 'I <b>really</b> like evil code >_< <script type="text/javascript">doSomethingBad();</script>', '1'),
])),
)
self.assertEqual(comparison.htmldiff(), '<div class="comparison__child-object">I really like <span class="deletion">Wagtail <3</span><span class="addition">evil code >_< doSomethingBad();</span></div>')
self.assertIsInstance(comparison.htmldiff(), SafeString)