web/lib/django_extensions/utils/text.py
changeset 3 526ebd3988b0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/web/lib/django_extensions/utils/text.py	Wed Jan 20 12:37:40 2010 +0100
@@ -0,0 +1,13 @@
+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)