本文整理汇总了Python中django.utils.lorem_ipsum.paragraphs方法的典型用法代码示例。如果您正苦于以下问题:Python lorem_ipsum.paragraphs方法的具体用法?Python lorem_ipsum.paragraphs怎么用?Python lorem_ipsum.paragraphs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.lorem_ipsum
的用法示例。
在下文中一共展示了lorem_ipsum.paragraphs方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_paragraphs_not_common
# 需要导入模块: from django.utils import lorem_ipsum [as 别名]
# 或者: from django.utils.lorem_ipsum import paragraphs [as 别名]
def test_paragraphs_not_common(self, mock_randint, mock_choice, mock_sample):
"""
paragraphs(1, common=False) generating one paragraph that's not the
COMMON_P paragraph.
"""
# Make creating 2 sentences use 2 phrases.
mock_randint.return_value = 2
mock_sample.return_value = ['exercitationem', 'perferendis']
mock_choice.return_value = '.'
self.assertEqual(
paragraphs(1, common=False),
[
'Exercitationem perferendis, exercitationem perferendis. '
'Exercitationem perferendis, exercitationem perferendis.'
]
)
self.assertEqual(mock_randint.call_count, 7)
示例2: render
# 需要导入模块: from django.utils import lorem_ipsum [as 别名]
# 或者: from django.utils.lorem_ipsum import paragraphs [as 别名]
def render(self, context):
try:
count = int(self.count.resolve(context))
except (ValueError, TypeError):
count = 1
if self.method == 'w':
return words(count, common=self.common)
else:
paras = paragraphs(count, common=self.common)
if self.method == 'p':
paras = ['<p>%s</p>' % p for p in paras]
return '\n\n'.join(paras)
示例3: test_paragraphs
# 需要导入模块: from django.utils import lorem_ipsum [as 别名]
# 或者: from django.utils.lorem_ipsum import paragraphs [as 别名]
def test_paragraphs(self):
"""paragraphs(1) uses the COMMON_P paragraph."""
self.assertEqual(
paragraphs(1), [
'Lorem ipsum dolor sit amet, consectetur adipisicing elit, '
'sed do eiusmod tempor incididunt ut labore et dolore magna '
'aliqua. Ut enim ad minim veniam, quis nostrud exercitation '
'ullamco laboris nisi ut aliquip ex ea commodo consequat. '
'Duis aute irure dolor in reprehenderit in voluptate velit '
'esse cillum dolore eu fugiat nulla pariatur. Excepteur sint '
'occaecat cupidatat non proident, sunt in culpa qui officia '
'deserunt mollit anim id est laborum.'
]
)
示例4: lorem
# 需要导入模块: from django.utils import lorem_ipsum [as 别名]
# 或者: from django.utils.lorem_ipsum import paragraphs [as 别名]
def lorem(parser, token):
"""
Creates random Latin text useful for providing test data in templates.
Usage format::
{% lorem [count] [method] [random] %}
``count`` is a number (or variable) containing the number of paragraphs or
words to generate (default is 1).
``method`` is either ``w`` for words, ``p`` for HTML paragraphs, ``b`` for
plain-text paragraph blocks (default is ``b``).
``random`` is the word ``random``, which if given, does not use the common
paragraph (starting "Lorem ipsum dolor sit amet, consectetuer...").
Examples:
* ``{% lorem %}`` will output the common "lorem ipsum" paragraph
* ``{% lorem 3 p %}`` will output the common "lorem ipsum" paragraph
and two random paragraphs each wrapped in HTML ``<p>`` tags
* ``{% lorem 2 w random %}`` will output two random latin words
"""
bits = list(token.split_contents())
tagname = bits[0]
# Random bit
common = bits[-1] != 'random'
if not common:
bits.pop()
# Method bit
if bits[-1] in ('w', 'p', 'b'):
method = bits.pop()
else:
method = 'b'
# Count bit
if len(bits) > 1:
count = bits.pop()
else:
count = '1'
count = parser.compile_filter(count)
if len(bits) != 1:
raise TemplateSyntaxError("Incorrect format for %r tag" % tagname)
return LoremNode(count, method, common)
示例5: lorem
# 需要导入模块: from django.utils import lorem_ipsum [as 别名]
# 或者: from django.utils.lorem_ipsum import paragraphs [as 别名]
def lorem(parser, token):
"""
Create random Latin text useful for providing test data in templates.
Usage format::
{% lorem [count] [method] [random] %}
``count`` is a number (or variable) containing the number of paragraphs or
words to generate (default is 1).
``method`` is either ``w`` for words, ``p`` for HTML paragraphs, ``b`` for
plain-text paragraph blocks (default is ``b``).
``random`` is the word ``random``, which if given, does not use the common
paragraph (starting "Lorem ipsum dolor sit amet, consectetuer...").
Examples:
* ``{% lorem %}`` outputs the common "lorem ipsum" paragraph
* ``{% lorem 3 p %}`` outputs the common "lorem ipsum" paragraph
and two random paragraphs each wrapped in HTML ``<p>`` tags
* ``{% lorem 2 w random %}`` outputs two random latin words
"""
bits = list(token.split_contents())
tagname = bits[0]
# Random bit
common = bits[-1] != 'random'
if not common:
bits.pop()
# Method bit
if bits[-1] in ('w', 'p', 'b'):
method = bits.pop()
else:
method = 'b'
# Count bit
if len(bits) > 1:
count = bits.pop()
else:
count = '1'
count = parser.compile_filter(count)
if len(bits) != 1:
raise TemplateSyntaxError("Incorrect format for %r tag" % tagname)
return LoremNode(count, method, common)