diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index 32a1900cb1..c5cde4b14d 100644 --- a/django/contrib/admin/widgets.py +++ b/django/contrib/admin/widgets.py @@ -193,7 +193,7 @@ class ForeignKeyRawIdWidget(forms.TextInput): except NoReverseMatch: url = '' # Admin not registered for target model. - return Truncator(obj).words(14, truncate='...'), url + return Truncator(obj).words(14), url class ManyToManyRawIdWidget(ForeignKeyRawIdWidget): diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index 400ce7ceb5..1479da8788 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -280,7 +280,7 @@ def truncatewords(value, arg): length = int(arg) except ValueError: # Invalid literal for int(). return value # Fail silently. - return Truncator(value).words(length, truncate=' ...') + return Truncator(value).words(length, truncate=' …') @register.filter(is_safe=True) @@ -294,7 +294,7 @@ def truncatewords_html(value, arg): length = int(arg) except ValueError: # invalid literal for int() return value # Fail silently. - return Truncator(value).words(length, html=True, truncate=' ...') + return Truncator(value).words(length, html=True, truncate=' …') @register.filter(is_safe=False) diff --git a/django/utils/html.py b/django/utils/html.py index c5035e3b23..72719cdd2d 100644 --- a/django/utils/html.py +++ b/django/utils/html.py @@ -245,7 +245,7 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False): leading punctuation (opening parens) and it'll still do the right thing. If trim_url_limit is not None, truncate the URLs in the link text longer - than this limit to trim_url_limit-3 characters and append an ellipsis. + than this limit to trim_url_limit - 1 characters and append an ellipsis. If nofollow is True, give the links a rel="nofollow" attribute. @@ -256,7 +256,7 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False): def trim_url(x, limit=trim_url_limit): if limit is None or len(x) <= limit: return x - return '%s...' % x[:max(0, limit - 3)] + return '%s…' % x[:max(0, limit - 1)] def unescape(text, trail): """ diff --git a/django/utils/text.py b/django/utils/text.py index e980f7170f..0e41cac493 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -64,7 +64,7 @@ class Truncator(SimpleLazyObject): if truncate is None: truncate = pgettext( 'String to return when truncating text', - '%(truncated_text)s...') + '%(truncated_text)s…') if '%(truncated_text)s' in truncate: return truncate % {'truncated_text': text} # The truncation text didn't contain the %(truncated_text)s string @@ -81,8 +81,7 @@ class Truncator(SimpleLazyObject): of characters. `truncate` specifies what should be used to notify that the string has - been truncated, defaulting to a translatable string of an ellipsis - (...). + been truncated, defaulting to a translatable string of an ellipsis. """ self._setup() length = int(num) @@ -123,7 +122,7 @@ class Truncator(SimpleLazyObject): """ Truncate a string after a certain number of words. `truncate` specifies what should be used to notify that the string has been truncated, - defaulting to ellipsis (...). + defaulting to ellipsis. """ self._setup() length = int(num) diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt index 0d2ba1b08a..e5507e3714 100644 --- a/docs/ref/templates/builtins.txt +++ b/docs/ref/templates/builtins.txt @@ -2265,15 +2265,15 @@ If ``value`` is ``"my FIRST post"``, the output will be ``"My First Post"``. ----------------- Truncates a string if it is longer than the specified number of characters. -Truncated strings will end with a translatable ellipsis sequence ("..."). +Truncated strings will end with a translatable ellipsis character ("…"). **Argument:** Number of characters to truncate to For example:: - {{ value|truncatechars:9 }} + {{ value|truncatechars:7 }} -If ``value`` is ``"Joel is a slug"``, the output will be ``"Joel i..."``. +If ``value`` is ``"Joel is a slug"``, the output will be ``"Joel i…"``. .. templatefilter:: truncatechars_html @@ -2286,10 +2286,10 @@ are closed immediately after the truncation. For example:: - {{ value|truncatechars_html:9 }} + {{ value|truncatechars_html:7 }} If ``value`` is ``"
Joel is a slug
"``, the output will be -``"Joel i...
"``. +``"Joel i…
"``. Newlines in the HTML content will be preserved. @@ -2306,7 +2306,7 @@ For example:: {{ value|truncatewords:2 }} -If ``value`` is ``"Joel is a slug"``, the output will be ``"Joel is ..."``. +If ``value`` is ``"Joel is a slug"``, the output will be ``"Joel is …"``. Newlines within the string will be removed. @@ -2327,7 +2327,7 @@ For example:: {{ value|truncatewords_html:2 }} If ``value`` is ``"Joel is a slug
"``, the output will be -``"Joel is ...
"``. +``"Joel is …
"``. Newlines in the HTML content will be preserved. @@ -2454,7 +2454,7 @@ For example:: If ``value`` is ``"Check out www.djangoproject.com"``, the output would be ``'Check out www.djangopr...'``. +rel="nofollow">www.djangoproj…'``. As with urlize_, this filter should only be applied to plain text. diff --git a/docs/releases/2.2.txt b/docs/releases/2.2.txt index 307a2b6a06..4ca3bb9662 100644 --- a/docs/releases/2.2.txt +++ b/docs/releases/2.2.txt @@ -273,6 +273,12 @@ Miscellaneous * The return value of :func:`django.utils.text.slugify` is no longer marked as HTML safe. +* The default truncation character used by the :tfilter:`urlizetrunc`, + :tfilter:`truncatechars`, :tfilter:`truncatechars_html`, + :tfilter:`truncatewords`, and :tfilter:`truncatewords_html` template filters + is now the real ellipsis character (``…``) instead of 3 dots. You may have to + adapt some test output comparisons. + .. _deprecated-features-2.2: Features deprecated in 2.2 diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py index 3bc37b6c15..c216b10e68 100644 --- a/tests/migrations/test_commands.py +++ b/tests/migrations/test_commands.py @@ -346,7 +346,7 @@ class MigrateTests(MigrationTestBase): self.assertEqual( 'Planned operations:\n' 'migrations.0004_fourth\n' - ' Raw SQL operation -> SELECT * FROM migrations_author W...\n', + ' Raw SQL operation -> SELECT * FROM migrations_author WHE…\n', out.getvalue() ) # Migrate to the fourth migration. diff --git a/tests/template_tests/filter_tests/test_truncatechars.py b/tests/template_tests/filter_tests/test_truncatechars.py index 81083c3b9c..89d48fd1cf 100644 --- a/tests/template_tests/filter_tests/test_truncatechars.py +++ b/tests/template_tests/filter_tests/test_truncatechars.py @@ -5,10 +5,10 @@ from ..utils import setup class TruncatecharsTests(SimpleTestCase): - @setup({'truncatechars01': '{{ a|truncatechars:5 }}'}) + @setup({'truncatechars01': '{{ a|truncatechars:3 }}'}) def test_truncatechars01(self): output = self.engine.render_to_string('truncatechars01', {'a': 'Testing, testing'}) - self.assertEqual(output, 'Te...') + self.assertEqual(output, 'Te…') @setup({'truncatechars02': '{{ a|truncatechars:7 }}'}) def test_truncatechars02(self): diff --git a/tests/template_tests/filter_tests/test_truncatechars_html.py b/tests/template_tests/filter_tests/test_truncatechars_html.py index 77e41a74ac..4948e6534e 100644 --- a/tests/template_tests/filter_tests/test_truncatechars_html.py +++ b/tests/template_tests/filter_tests/test_truncatechars_html.py @@ -5,18 +5,18 @@ from django.test import SimpleTestCase class FunctionTests(SimpleTestCase): def test_truncate_zero(self): - self.assertEqual(truncatechars_html('one two - three
four five
one two - three
four five
one two - three
four five
one...
', + truncatechars_html('one two - three
four five
one…
', ) def test_truncate2(self): self.assertEqual( - truncatechars_html('one two - three
four five
one two ...
', + truncatechars_html('one two - three
four five
one two …
', ) def test_truncate3(self): @@ -26,7 +26,7 @@ class FunctionTests(SimpleTestCase): ) def test_truncate_unicode(self): - self.assertEqual(truncatechars_html('\xc5ngstr\xf6m was here', 5), '\xc5n...') + self.assertEqual(truncatechars_html('\xc5ngstr\xf6m was here', 3), '\xc5n…') def test_truncate_something(self): self.assertEqual(truncatechars_html('abc', 3), 'abc') diff --git a/tests/template_tests/filter_tests/test_truncatewords.py b/tests/template_tests/filter_tests/test_truncatewords.py index 4941e736fd..636cd55fd5 100644 --- a/tests/template_tests/filter_tests/test_truncatewords.py +++ b/tests/template_tests/filter_tests/test_truncatewords.py @@ -14,25 +14,25 @@ class TruncatewordsTests(SimpleTestCase): output = self.engine.render_to_string( 'truncatewords01', {'a': 'alpha & bravo', 'b': mark_safe('alpha & bravo')} ) - self.assertEqual(output, 'alpha & ... alpha & ...') + self.assertEqual(output, 'alpha & … alpha & …') @setup({'truncatewords02': '{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}'}) def test_truncatewords02(self): output = self.engine.render_to_string( 'truncatewords02', {'a': 'alpha & bravo', 'b': mark_safe('alpha & bravo')} ) - self.assertEqual(output, 'alpha & ... alpha & ...') + self.assertEqual(output, 'alpha & … alpha & …') class FunctionTests(SimpleTestCase): def test_truncate(self): - self.assertEqual(truncatewords('A sentence with a few words in it', 1), 'A ...') + self.assertEqual(truncatewords('A sentence with a few words in it', 1), 'A …') def test_truncate2(self): self.assertEqual( truncatewords('A sentence with a few words in it', 5), - 'A sentence with a few ...', + 'A sentence with a few …', ) def test_overtruncate(self): diff --git a/tests/template_tests/filter_tests/test_truncatewords_html.py b/tests/template_tests/filter_tests/test_truncatewords_html.py index 2db4b3f926..5daeef6cf3 100644 --- a/tests/template_tests/filter_tests/test_truncatewords_html.py +++ b/tests/template_tests/filter_tests/test_truncatewords_html.py @@ -10,13 +10,13 @@ class FunctionTests(SimpleTestCase): def test_truncate(self): self.assertEqual( truncatewords_html('one two - three
four five
one two ...
', + 'one two …
', ) def test_truncate2(self): self.assertEqual( truncatewords_html('one two - three
four five
The quick brown fox...
', + 'The quick brown fox…
', truncator.words(4, html=True) ) self.assertEqual( @@ -121,21 +121,21 @@ class TestUtilsText(SimpleTestCase): 'The quick brown fox jumped over the lazy dog.
' ) self.assertEqual( - 'The quick brown...
', - truncator.words(3, '...', html=True) + 'The quick brown…
', + truncator.words(3, html=True) ) # Test self-closing tags truncator = text.Truncator('I <3 python, what about you?
') - self.assertEqual('I <3 python...
', truncator.words(3, '...', html=True)) + self.assertEqual('I <3 python…
', truncator.words(3, html=True)) re_tag_catastrophic_test = ('' truncator = text.Truncator(re_tag_catastrophic_test)