On Wed, Dec 30, 2009 at 8:15 AM, Nic Pottier <nicpott...@gmail.com> wrote: > > New to Django, but certainly not web development. After being > pleasantly surprised with a lot of the available Django filters I was > rather surprised not to see a string truncation filter included. > > A little googling shows I'm not the only one, there are tons of people > writing their own filters to accomplish this, and sure enough a nice > looking patch submitted two (TWO!) years ago to add a |truncate. > > I'd be curious to hear what the reason for not accepting this patch > is. String truncation is a pretty common task, and having it built in > seems like a no-brainer.
I disagree. Firstly, as James points out, slice already exists, and the ellipsis difference between slice and truncate can be easily overcome with additional code. Secondly, IMHO raw truncation based on characters is bad practice for human readable text. A sentence is composed of words, not characters. Truncating a sentence mid-word isn't a typographical practice that I particularly want to encourage. I would be marginally more inclined to support a truncate filter that obeyed word boundaries i.e., no more than 50 characters, but stop at the end of the last complete word. However, even with this modification - what's the use case for an N character truncation? It can't (or shouldn't be) to make sure that text will fit into a visual space. You can't guarantee how wide N characters will be at render-time due to differences in character width. If you want to truncate for display purposes, you should be looking at CSS overflow properties or other display-level tricks. So - put me down as -0 as well. I just don't see that there is a huge gain in adding another built-in filter. If you really have a need for this filter, it's easy to support it as an external library. As for why this patch has languished for so long - one major reason is that nobody has made an issue of it previously. By my count, this thread is only the third time that someone has made the case for a built-in truncate filter, and one of those times was as a late addition to a thread about adding a completely different bunch of tags. Yours, Russ Magee %-) -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-develop...@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.