web/lib/django_extensions/utils/text.py
author ymh <ymh.work@gmail.com>
Fri, 04 Mar 2011 16:45:48 +0100
changeset 57 1984c3b5f299
parent 3 526ebd3988b0
permissions -rw-r--r--
Create new version

from django.utils.encoding import force_unicode
from django.utils.functional import allow_lazy

def truncate_letters(s, num):
    """ truncates a string to a number of letters, similar to truncate_words """
    s = force_unicode(s)
    length = int(num)
    if len(s)>length:
        s = s[:length]
    if not s.endswith('...'):
        s += '...'
    return s
truncate_letters = allow_lazy(truncate_letters, unicode)