Skip to content
This repository
Browse code

Replace truncate_words by Truncator.chars

This fixes a lot of deprecation warnings in Django 1.5. Truncator is
supported in both Django 1.4 and Django 1.5.

The original code could result in double ellipsis. This commit simplifies
the logic and only relies on Truncator.chars which feels like a better
way of truncating the text anyways.
  • Loading branch information...
commit 7c9d6cf1c8d0cf4a999321f4f64b8df509e210f9 1 parent dfd4015
Michael P. Jung authored March 27, 2013

Showing 1 changed file with 3 additions and 3 deletions. Show diff stats Hide diff stats

  1. 6  cms/plugins/text/models.py
6  cms/plugins/text/models.py
@@ -4,7 +4,7 @@
4 4
 from cms.utils.html import clean_html
5 5
 from django.db import models
6 6
 from django.utils.html import strip_tags
7  
-from django.utils.text import truncate_words
  7
+from django.utils.text import Truncator
8 8
 from django.utils.translation import ugettext_lazy as _
9 9
 
10 10
 _old_tree_cache = {}
@@ -32,7 +32,7 @@ def _get_body_admin(self):
32 32
     search_fields = ('body',)
33 33
     
34 34
     def __unicode__(self):
35  
-        return u"%s" % (truncate_words(strip_tags(self.body), 3)[:30]+"...")
  35
+        return Truncator(strip_tags(self.body)).chars(30)
36 36
     
37 37
     def clean(self):
38 38
         self.body = clean_html(self.body, full=False)
@@ -60,4 +60,4 @@ class Text(AbstractText):
60 60
     """
61 61
     Actual Text Class
62 62
     """
63  
-    
  63
+    

0 notes on commit 7c9d6cf

Please sign in to comment.
Something went wrong with that request. Please try again.