-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #22789 -- Deprecated django.contrib.webdesign.
Moved the {% lorem %} tag to built-in tags.
- Loading branch information
Showing
11 changed files
with
150 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
import warnings | ||
|
||
from django.utils.deprecation import RemovedInDjango20Warning | ||
|
||
default_app_config = 'django.contrib.webdesign.apps.WebDesignConfig' | ||
|
||
warnings.warn( | ||
"django.contrib.webdesign will be removed in Django 2.0. The " | ||
"{% lorem %} tag is now included in the built-in tags.", | ||
RemovedInDjango20Warning | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,6 @@ | ||
from __future__ import unicode_literals | ||
|
||
from django.contrib.webdesign.lorem_ipsum import words, paragraphs | ||
from django import template | ||
from django.template.defaulttags import lorem | ||
|
||
register = template.Library() | ||
|
||
|
||
class LoremNode(template.Node): | ||
def __init__(self, count, method, common): | ||
self.count, self.method, self.common = count, method, common | ||
|
||
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) | ||
|
||
|
||
@register.tag | ||
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 template.TemplateSyntaxError("Incorrect format for %r tag" % tagname) | ||
return LoremNode(count, method, common) | ||
register.tag(lorem) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
import unittest | ||
|
||
from django.utils.lorem_ipsum import paragraphs, words | ||
|
||
|
||
class WebdesignTest(unittest.TestCase): | ||
|
||
def test_words(self): | ||
self.assertEqual(words(7), 'lorem ipsum dolor sit amet consectetur adipisicing') | ||
|
||
def test_paragraphs(self): | ||
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.']) |