summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2018-12-11 14:00:16 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2018-12-11 14:00:16 (GMT)
commitf114291004c2fdcb4952a68ead2cf89d8f75072b (patch)
tree3dfa16e9487e8862a0edf2bc05b7156069585943
parentd1642e2b0f827c4889faa0400e2d0dd3cb074b72 (diff)
downloadwelco-f114291004c2fdcb4952a68ead2cf89d8f75072b.zip
welco-f114291004c2fdcb4952a68ead2cf89d8f75072b.tar.gz
welco-f114291004c2fdcb4952a68ead2cf89d8f75072b.tar.bz2
misc: add ckeditor monkeypatch for 1.11 (#28864)v0.65
-rw-r--r--welco/__init__.py18
-rw-r--r--welco/monkeypatch.py53
2 files changed, 71 insertions, 0 deletions
diff --git a/welco/__init__.py b/welco/__init__.py
index e69de29..9b88209 100644
--- a/welco/__init__.py
+++ b/welco/__init__.py
@@ -0,0 +1,18 @@
+# welco - multichannel request processing
+# Copyright (C) 2015-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 <http://www.gnu.org/licenses/>.
+
+
+import welco.monkeypatch
diff --git a/welco/monkeypatch.py b/welco/monkeypatch.py
new file mode 100644
index 0000000..d3f8010
--- /dev/null
+++ b/welco/monkeypatch.py
@@ -0,0 +1,53 @@
+# welco - multichannel request processing
+# 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 <http://www.gnu.org/licenses/>.
+
+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 getattr(self, 'attrs', None):
+ final_attrs.update(self.attrs)
+ 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