misc: use Truncator in ellipsize (#42744)

This commit is contained in:
Lauréline Guérin 2020-08-28 15:40:24 +02:00
parent 1f4ac8d124
commit 0df992678e
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
1 changed files with 3 additions and 2 deletions

View File

@ -39,10 +39,11 @@ from django.utils import datetime_safe
from django.utils import six
from django.utils.encoding import force_text
from django.utils.html import strip_tags
from django.template import engines, TemplateSyntaxError, VariableDoesNotExist
from django.template import TemplateSyntaxError, VariableDoesNotExist
from django.utils.six.moves.html_parser import HTMLParser
from django.utils.six.moves.urllib.parse import quote, urlencode
from django.utils.six.moves.urllib import parse as urlparse
from django.utils.text import Truncator
from quixote import get_publisher, get_response, get_request, redirect
from quixote.html import htmltext
@ -263,7 +264,7 @@ def ellipsize(s, length=30):
s = force_text(s, get_publisher().site_charset, errors='replace')
if s and len(s) > length:
if length > 3:
s = s[:length-3] + '(…)'
s = Truncator(s).chars(length, truncate='(…)')
else:
s = s[:length]
return force_str(s)