Fixed #19496 -- Added truncatechars_html filter. #1689

Closed
wants to merge 12 commits into
from

Conversation

Projects
None yet
3 participants
@saturn597
Contributor

saturn597 commented Sep 29, 2013

truncatechars_html was incorrectly adding the '...' to text under the truncate length but only by 3 or fewer characters.

>>> truncatechars_html('abcd', 4)
u'a...'

It now correctly returns:

>>> truncatechars_html('abcd', 4)
u'abcd'

@timgraham timgraham referenced this pull request Oct 1, 2013

Closed

truncatechars_html #1126

docs/releases/1.6.txt
@@ -372,6 +372,11 @@ Minor features
default value.
+* ``truncatechars_html`` template filter. This new filter truncates a string

This comment has been minimized.

@timgraham

timgraham Oct 7, 2013

Member

1.6 is feature frozen, so this should be moved to the 1.7 release notes.

@timgraham

timgraham Oct 7, 2013

Member

1.6 is feature frozen, so this should be moved to the 1.7 release notes.

docs/ref/templates/builtins.txt
@@ -2143,6 +2143,26 @@ If ``value`` is ``"Joel is a slug"``, the output will be ``"Joel i..."``.
.. templatefilter:: truncatewords

This comment has been minimized.

@timgraham

timgraham Oct 7, 2013

Member

there's an extra heading for truncatewords here

@timgraham

timgraham Oct 7, 2013

Member

there's an extra heading for truncatewords here

+
+truncatechars_html
+^^^^^^^^^^^^^^^^^^
+

This comment has been minimized.

@timgraham

timgraham Oct 7, 2013

Member

needs .. versionadded:: 1.7

@timgraham

timgraham Oct 7, 2013

Member

needs .. versionadded:: 1.7

django/utils/text.py
@@ -115,7 +123,73 @@ def chars(self, num, truncate=None):
# Return the original string since no truncation was necessary
return text
- chars = allow_lazy(chars)
+
+ def _html_chars(self, length, truncate, text, truncate_len):

This comment has been minimized.

@timgraham

timgraham Oct 7, 2013

Member

could this be refactored so there's less duplicated logic between _html_chars and _html_words, please?

@timgraham

timgraham Oct 7, 2013

Member

could this be refactored so there's less duplicated logic between _html_chars and _html_words, please?

@timgraham

This comment has been minimized.

Show comment
Hide comment
@timgraham

timgraham Feb 13, 2014

Member

merged in f94f466, thanks.

Member

timgraham commented Feb 13, 2014

merged in f94f466, thanks.

@timgraham timgraham closed this Feb 13, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment