From 253a9d7af64d16a0a6ce092ea88b35f9cea5cf1a Mon Sep 17 00:00:00 2001 From: Simon Fransson Date: Fri, 17 Oct 2014 00:06:25 +0200 Subject: [PATCH 1/4] Made get_image_files() exclude hidden files (leading . in filename). --- ckeditor/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckeditor/views.py b/ckeditor/views.py index 336001b..3223581 100644 --- a/ckeditor/views.py +++ b/ckeditor/views.py @@ -98,7 +98,7 @@ def get_image_files(user=None, path=''): return for filename in storage_list[STORAGE_FILES]: - if os.path.splitext(filename)[0].endswith('_thumb'): + if os.path.splitext(filename)[0].endswith('_thumb') or os.path.basename(filename).startswith('.'): continue filename = os.path.join(browse_path, filename) yield filename From 0526219288a243b044584415157c740d4d66e487 Mon Sep 17 00:00:00 2001 From: Simon Fransson Date: Fri, 17 Oct 2014 00:08:16 +0200 Subject: [PATCH 2/4] Added never_cache() decorator to browse view, as the it often did not display newly uploaded files after being loaded once. --- ckeditor/urls.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ckeditor/urls.py b/ckeditor/urls.py index a88bb0d..e8a3d70 100644 --- a/ckeditor/urls.py +++ b/ckeditor/urls.py @@ -1,10 +1,11 @@ from django.conf.urls import patterns, url from django.contrib.admin.views.decorators import staff_member_required +from django.views.decorators.cache import never_cache from ckeditor import views urlpatterns = patterns( '', url(r'^upload/', staff_member_required(views.upload), name='ckeditor_upload'), - url(r'^browse/', staff_member_required(views.browse), name='ckeditor_browse'), + url(r'^browse/', never_cache(staff_member_required(views.browse)), name='ckeditor_browse'), ) From d441e27239b8a15462b439199a8c57c5fb47f00f Mon Sep 17 00:00:00 2001 From: Nathan Long Date: Fri, 17 Oct 2014 14:25:52 -0400 Subject: [PATCH 3/4] Set $ to django.jQuery if $ not defined, organize ckeditor-init.js, replace .click(...) with delegated .on(...) in case elements do not exist when code is run --- ckeditor/static/ckeditor/ckeditor-init.js | 27 +++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/ckeditor/static/ckeditor/ckeditor-init.js b/ckeditor/static/ckeditor/ckeditor-init.js index de939a5..358a8a2 100644 --- a/ckeditor/static/ckeditor/ckeditor-init.js +++ b/ckeditor/static/ckeditor/ckeditor-init.js @@ -1,20 +1,23 @@ -$(function() { +;(function() { + var $ = $ || django.jQuery; + $(function() { initialiseCKEditor(); initialiseCKEditorInInlinedForms(); function initialiseCKEditorInInlinedForms() { - $(".add-row a, .grp-add-handler").click(function () { - initialiseCKEditor(); - return true; - }); + $(document).on("click", ".add-row a, .grp-add-handler", function () { + initialiseCKEditor(); + return true; + }); } -}); -function initialiseCKEditor() { - $('textarea[data-type=ckeditortype]').each(function(){ + function initialiseCKEditor() { + $('textarea[data-type=ckeditortype]').each(function(){ if($(this).data('processed') == "0" && $(this).attr('id').indexOf('__prefix__') == -1){ - $(this).data('processed',"1"); - CKEDITOR.replace($(this).attr('id'), $(this).data('config')); + $(this).data('processed',"1"); + CKEDITOR.replace($(this).attr('id'), $(this).data('config')); } - }); -} + }); + }; + }); +}()); From a5f6d2fcad7c7ecde09f129a6348b626d399eda4 Mon Sep 17 00:00:00 2001 From: Simon Fransson Date: Wed, 22 Oct 2014 13:49:17 +0200 Subject: [PATCH 4/4] Added lazy JSON encoder in order to support i18n in CKEditor settings A LazyEncoder has been implemented based on Djangos DjangoJSONEncoder, rather than json.JSONEncoder, as described [here](https://docs.djangoproject.com/en/dev/topics/serialization/#serialization-formats-json) This allows us to use `ugettext_lazy` (and other laze functions) in `settings.py` which adds the possibility to localize strings for use in the `CKEDITOR_CONFIGS` settings etc. **Example** from django.utils.translation import ugettext_lazy as _ CKEDITOR_CONFIGS = { 'default': { 'stylesSet': [ { 'name': _('Lead') , 'element': 'p', 'attributes': { 'class': 'lead' } }, ... ] ... } --- ckeditor/widgets.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ckeditor/widgets.py b/ckeditor/widgets.py index c322be8..bf68d59 100644 --- a/ckeditor/widgets.py +++ b/ckeditor/widgets.py @@ -8,10 +8,19 @@ from django.utils.encoding import force_text from django.utils.translation import get_language from django.core.exceptions import ImproperlyConfigured from django.forms.util import flatatt -import json + +from django.utils.functional import Promise +from django.utils.encoding import force_text +from django.core.serializers.json import DjangoJSONEncoder + +class LazyEncoder(DjangoJSONEncoder): + def default(self, obj): + if isinstance(obj, Promise): + return force_text(obj) + return super(LazyEncoder, self).default(obj) -json_encode = json.JSONEncoder().encode +json_encode = LazyEncoder().encode DEFAULT_CONFIG = { 'skin': 'moono',