misc: use Truncator in ellipsize (#42744)
This commit is contained in:
parent
1f4ac8d124
commit
0df992678e
|
@ -39,10 +39,11 @@ from django.utils import datetime_safe
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_text
|
||||||
from django.utils.html import strip_tags
|
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.html_parser import HTMLParser
|
||||||
from django.utils.six.moves.urllib.parse import quote, urlencode
|
from django.utils.six.moves.urllib.parse import quote, urlencode
|
||||||
from django.utils.six.moves.urllib import parse as urlparse
|
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 import get_publisher, get_response, get_request, redirect
|
||||||
from quixote.html import htmltext
|
from quixote.html import htmltext
|
||||||
|
@ -263,7 +264,7 @@ def ellipsize(s, length=30):
|
||||||
s = force_text(s, get_publisher().site_charset, errors='replace')
|
s = force_text(s, get_publisher().site_charset, errors='replace')
|
||||||
if s and len(s) > length:
|
if s and len(s) > length:
|
||||||
if length > 3:
|
if length > 3:
|
||||||
s = s[:length-3] + '(…)'
|
s = Truncator(s).chars(length, truncate='(…)')
|
||||||
else:
|
else:
|
||||||
s = s[:length]
|
s = s[:length]
|
||||||
return force_str(s)
|
return force_str(s)
|
||||||
|
|
Loading…
Reference in New Issue