1 2 3 4 5 6 7 8 9 10 11 12 13 | from django import template
register = template.Library()
@register.filter("inline_truncate")
def inline_truncate(value, size):
"""Truncates a string to the given size placing the ellipsis at the middle of the string"""
if len(value) > size and size > 3:
start = (size - 3) / 2
end = (size - 3) - start
return value[0:start] + '...' + value[-end:]
else:
return value[0:size]
|
Comments