Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adds compatibility fallback for truncate_words

  • Loading branch information...
commit 16f1e7e11fba9516f2cc7302d45d3c55b453284d 1 parent 3d18fe1
Stefan Foulis authored
2  filer/fields/file.py
View
@@ -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
2  filer/fields/folder.py
View
@@ -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
12 filer/utils/compatibility.py
View
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.