From 65c9934936f1e59c6c344428dfd1a189043af999 Mon Sep 17 00:00:00 2001 From: Jonathan Liuti Date: Sun, 25 May 2014 15:39:43 +0200 Subject: [PATCH 1/2] Fix #129, force_unicode on body to make sure it's not a proxy object anymore --- djangocms_text_ckeditor/models.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/djangocms_text_ckeditor/models.py b/djangocms_text_ckeditor/models.py index 60bbc54..be7777c 100644 --- a/djangocms_text_ckeditor/models.py +++ b/djangocms_text_ckeditor/models.py @@ -1,12 +1,16 @@ import re +import sys + +from django.utils.encoding import force_unicode from django.db import models -from cms.models import CMSPlugin from django.utils.html import strip_tags from django.utils.text import Truncator from django.utils.translation import ugettext_lazy as _ -import sys -from djangocms_text_ckeditor.utils import plugin_tags_to_id_list, replace_plugin_tags, plugin_to_tag -from djangocms_text_ckeditor.html import clean_html, extract_images + +from cms.models import CMSPlugin + +from .utils import plugin_tags_to_id_list, replace_plugin_tags, plugin_to_tag +from .html import clean_html, extract_images class AbstractText(CMSPlugin): @@ -22,6 +26,10 @@ class AbstractText(CMSPlugin): def __unicode__(self): return Truncator(strip_tags(self.body)).words(3, truncate="...") + def __init__(self, *args, **kwargs): + super(AbstractText, self).__init__(*args, **kwargs) + self.body = force_unicode(self.body) + def save(self, *args, **kwargs): body = self.body body = extract_images(body, self) From be659a9df5ba9b5720cae8f4418a09bde4901fe4 Mon Sep 17 00:00:00 2001 From: Jonathan Liuti Date: Sun, 25 May 2014 16:12:04 +0200 Subject: [PATCH 2/2] Use force_text for django 1.5+ on yakky's recommendation --- djangocms_text_ckeditor/models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/djangocms_text_ckeditor/models.py b/djangocms_text_ckeditor/models.py index be7777c..1025a5d 100644 --- a/djangocms_text_ckeditor/models.py +++ b/djangocms_text_ckeditor/models.py @@ -1,6 +1,11 @@ import re import sys +try: + from django.utils.encoding import force_text as force_unicode_or_text +except ImportError: + from django.utils.encoding import force_unicode as force_unicode_or_text + from django.utils.encoding import force_unicode from django.db import models from django.utils.html import strip_tags @@ -28,7 +33,7 @@ class AbstractText(CMSPlugin): def __init__(self, *args, **kwargs): super(AbstractText, self).__init__(*args, **kwargs) - self.body = force_unicode(self.body) + self.body = force_unicode_or_text(self.body) def save(self, *args, **kwargs): body = self.body