Opened 14 years ago
Closed 14 years ago
#16325 closed Cleanup/optimization (invalid)
truncatewords_html and tables
Reported by: | anonymous | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I noticed, that using truncatewords_html does truncate words in tables too, but if truncation point were happen in middle of row, it would be cut in middle.
I'd recommend that this function wouldn't truncate in middle of row, but later, when that specific row ended.
Attachments (1)
Change History (2)
by , 14 years ago
Attachment: | example.png added |
---|
comment:1 by , 14 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
truncatewords_html
behaves according to the documentation, and it's already quite complex, see:
- https://code.djangoproject.com/browser/django/trunk/django/template/defaultfilters.py#L263
- https://code.djangoproject.com/browser/django/trunk/django/utils/text.py#L56
I'm not in favor of modifying its behavior within tables, because one could raise similar arguments for other tags:
- <pre>: don't truncate before the end of line,
- <ul> or <ul>: <li> => don't truncate within a <li>,
- etc.
I don't think it's a good idea to go down this path.
truncatewords_html
just knows which tags need to be closed and which don't. It's a fairly simple and generic tag. If it doesn't do exactly what you need, you should write your own truncatetable
filter.
More generally, it doesn't make a lot of sense to truncate a table at a given number of words. It sounds more logical to truncate it at a given number of rows. That's one more reason to write your own filter.
Example of how it is and how it should behave.