| changeset 3 | 526ebd3988b0 |
| 1:ebaad720f88b | 3:526ebd3988b0 |
|---|---|
1 from django.utils.encoding import force_unicode |
|
2 from django.utils.functional import allow_lazy |
|
3 |
|
4 def truncate_letters(s, num): |
|
5 """ truncates a string to a number of letters, similar to truncate_words """ |
|
6 s = force_unicode(s) |
|
7 length = int(num) |
|
8 if len(s)>length: |
|
9 s = s[:length] |
|
10 if not s.endswith('...'): |
|
11 s += '...' |
|
12 return s |
|
13 truncate_letters = allow_lazy(truncate_letters, unicode) |