From 6ec93b92a8c07ef03eebc7934a6dcbf4f4a25109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Mon, 1 Jan 2018 11:44:19 +0100 Subject: [PATCH] misc: monkeypatch ckeditor render() method for 1.11 (#20917) --- combo/__init__.py | 2 ++ combo/monkeypatch.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 combo/monkeypatch.py diff --git a/combo/__init__.py b/combo/__init__.py index f6e18ca..a8a8752 100644 --- a/combo/__init__.py +++ b/combo/__init__.py @@ -13,3 +13,5 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . + +import combo.monkeypatch diff --git a/combo/monkeypatch.py b/combo/monkeypatch.py new file mode 100644 index 0000000..8ad9be2 --- /dev/null +++ b/combo/monkeypatch.py @@ -0,0 +1,51 @@ +# combo - content management system +# Copyright (C) 2018 Entr'ouvert +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from django.core.urlresolvers import reverse +from django.forms.utils import flatatt +from django.template.loader import render_to_string +from django.utils.encoding import force_text +from django.utils.html import conditional_escape +from django.utils.safestring import mark_safe +from django.utils.translation import get_language + +import ckeditor.widgets + +def ckeditor_render(self, name, value, attrs=None): + if value is None: + value = '' + final_attrs = {'name': name} + if attrs: + final_attrs.update(attrs) + if 'filebrowserUploadUrl' not in self.config: + self.config.setdefault('filebrowserUploadUrl', reverse('ckeditor_upload')) + if 'filebrowserBrowseUrl' not in self.config: + self.config.setdefault('filebrowserBrowseUrl', reverse('ckeditor_browse')) + if not self.config.get('language'): + self.config['language'] = get_language() + + # Force to text to evaluate possible lazy objects + external_plugin_resources = [[force_text(a), force_text(b), force_text(c)] for a, b, c in self.external_plugin_resources] + + return mark_safe(render_to_string('ckeditor/widget.html', { + 'final_attrs': flatatt(final_attrs), + 'value': conditional_escape(force_text(value)), + 'id': final_attrs['id'], + 'config': ckeditor.widgets.json_encode(self.config), + 'external_plugin_resources' : ckeditor.widgets.json_encode(external_plugin_resources) + })) + +ckeditor.widgets.CKEditorWidget.render = ckeditor_render -- 2.15.1