Opened 12 years ago

Closed 11 years ago

#19496 closed New feature (fixed)

truncatechars_html

Reported by: Stefano Vettorazzi Campos Owned by: Daniele Procida
Component: Template system Version: dev
Severity: Normal Keywords: truncatechars
Cc: saturn5971 Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Hi,
why don't have something like truncatewords_html for chars?
I don't have experience with the Django's source code, so I don't have a patch. But I can try if you want.

Change History (13)

comment:1 by Russell Keith-Magee, 12 years ago

Easy pickings: set
Triage Stage: UnreviewedAccepted

Sure; we've added truncatedchars; makes sense that there would be a HTML-sensitive equivalent.

comment:2 by Nick Sandford, 12 years ago

Has patch: set
Owner: changed from nobody to Nick Sandford
Status: newassigned

comment:3 by Nick Sandford, 12 years ago

Used truncatewords_html as a guideline, added docs & tests. All tests pass under sqlite. Pull request here: https://github.com/django/django/pull/633

comment:4 by DHessing, 12 years ago

Patch needs improvement: set
>>> truncatechars_html('<h1>test</h1>', 5)
u'<h1>t ...</h1>'

Should return u'<h1>te...</h1>'. Truncatewords adds an extra space in front of the ellipsis but truncatechars doesn't.

comment:5 by martmatwarne, 11 years ago

Owner: changed from Nick Sandford to martmatwarne

comment:6 by martmatwarne, 11 years ago

The above issue should now be fixed. It also appears to have broken truncatechars which I've now fixed

https://github.com/django/django/pull/1126

comment:7 by martmatwarne, 11 years ago

Actually there still appears to be issues when using html with only one tag pair in it

comment:8 by Daniele Procida, 11 years ago

I have marked this ticket as suitable for a first-time committer attending a Don't be afraid to commit workshop.

The next planned session will be hosted by Cardiff Dev Workshop on Saturday 8th June.

If you want to tackle this ticket before then, or at any time in fact, please don't let the fact that it's assigned to me stop you. Feel free to re-assign it to yourself and do whatever you like to it.

comment:9 by Daniele Procida, 11 years ago

Owner: changed from martmatwarne to Daniele Procida

comment:10 by saturn5971, 11 years ago

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

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

I've provided an updated patch here, including an addition to the test:

https://github.com/django/django/pull/1689

comment:11 by Tim Graham, 11 years ago

Easy pickings: unset
Version: 1.4master

I've left some comments on the PR for improvement.

comment:12 by saturn5971, 11 years ago

Cc: saturn5971 added
Keywords: truncatechars added; truncatchars removed

Thanks! I updated my pull request in accord with Timo's suggestions.

https://github.com/django/django/pull/1689

To eliminate redundant code between _html_chars and _html_words, I've collapsed them into a single function, _truncate_html. I made the requested documentation changes as well.

comment:13 by Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: assignedclosed

In f94f466cd3461527fb76a3e8951039a3c2388829:

Fixed #19496 -- Added truncatechars_html filter.

Thanks esevece for the suggestion and Nick Sandford and Martin Warne
for the inital work on the patch.

Note: See TracTickets for help on using tickets.
Back to Top