Commits

Alessandro Pagnin committed 4d846b2 Draft

- Support for django 1.5 (truncate_words is deprecated)

Comments (0)

Files changed (2)

postman/models.py

     from postman.future_1_5 import get_user_model
 from django.core.exceptions import ValidationError
 from django.db import models
-from django.utils.text import truncate_words
+from postman.utils import truncate_words
 from django.utils.translation import ugettext, ugettext_lazy as _
 try:
     from django.utils.timezone import now  # Django 1.4 aware datetimes
 else:
     from django.core.mail import send_mail
 
+try:
+    from django.utils.text import truncate_words
+except ImportError:
+    # django >=1.5
+    from django.utils.text import Truncator
+    from django.utils.functional import allow_lazy
+    def truncate_words(s, num, end_text='...'):
+        truncate = end_text and ' %s' % end_text or ''
+        return Truncator(s).words(num, truncate=truncate)
+    truncate_words = allow_lazy(truncate_words, unicode)
+
 # to disable email notification to users
 DISABLE_USER_EMAILING = getattr(settings, 'POSTMAN_DISABLE_USER_EMAILING', False)