Browse files

adds compatibility fallback for truncate_words

  • Loading branch information...
1 parent 3d18fe1 commit 16f1e7e11fba9516f2cc7302d45d3c55b453284d @stefanfoulis stefanfoulis committed Jan 5, 2013
Showing with 14 additions and 2 deletions.
  1. +1 −1 filer/fields/file.py
  2. +1 −1 filer/fields/folder.py
  3. +12 −0 filer/utils/compatibility.py
View
2 filer/fields/file.py
@@ -9,7 +9,7 @@
from django.db import models
from django.template.loader import render_to_string
from django.utils.safestring import mark_safe
-from django.utils.text import truncate_words
+from filer.utils.compatibility import truncate_words
from filer.models import File
from filer import settings as filer_settings
View
2 filer/fields/folder.py
@@ -8,7 +8,7 @@
from django.core.urlresolvers import reverse
from django.db import models
from django.utils.safestring import mark_safe
-from django.utils.text import truncate_words
+from filer.utils.compatibility import truncate_words
from django.utils.translation import ugettext as _
from filer.models import Folder
from filer.settings import FILER_STATICMEDIA_PREFIX
View
12 filer/utils/compatibility.py
@@ -0,0 +1,12 @@
+# -*- coding: utf-8 -*-
+
+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)

0 comments on commit 16f1e7e

Please sign in to comment.