Permalink
Browse files

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...
1 parent dfd4015 commit 7c9d6cf1c8d0cf4a999321f4f64b8df509e210f9 @bikeshedder bikeshedder committed Mar 27, 2013
Showing with 3 additions and 3 deletions.
  1. +3 −3 cms/plugins/text/models.py
@@ -4,7 +4,7 @@
from cms.utils.html import clean_html
from django.db import models
from django.utils.html import strip_tags
-from django.utils.text import truncate_words
+from django.utils.text import Truncator
from django.utils.translation import ugettext_lazy as _
_old_tree_cache = {}
@@ -32,7 +32,7 @@ def _get_body_admin(self):
search_fields = ('body',)
def __unicode__(self):
- return u"%s" % (truncate_words(strip_tags(self.body), 3)[:30]+"...")
+ return Truncator(strip_tags(self.body)).chars(30)
def clean(self):
self.body = clean_html(self.body, full=False)
@@ -60,4 +60,4 @@ class Text(AbstractText):
"""
Actual Text Class
"""
-
+

0 comments on commit 7c9d6cf

Please sign in to comment.