Projet

Général

Profil

0001-misc-add-ckeditor-monkeypatch-for-1.11-28864.patch

Frédéric Péters, 11 décembre 2018 15:01

Télécharger (3,81 ko)

Voir les différences:

Subject: [PATCH] misc: add ckeditor monkeypatch for 1.11 (#28864)

 welco/__init__.py    | 18 +++++++++++++++
 welco/monkeypatch.py | 53 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+)
 create mode 100644 welco/monkeypatch.py
welco/__init__.py
1
# welco - multichannel request processing
2
# Copyright (C) 2015-2018  Entr'ouvert
3
#
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU Affero General Public License as published
6
# by the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU Affero General Public License for more details.
13
#
14
# You should have received a copy of the GNU Affero General Public License
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16

  
17

  
18
import welco.monkeypatch
welco/monkeypatch.py
1
# welco - multichannel request processing
2
# Copyright (C) 2018  Entr'ouvert
3
#
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU Affero General Public License as published
6
# by the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU Affero General Public License for more details.
13
#
14
# You should have received a copy of the GNU Affero General Public License
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16

  
17
from django.core.urlresolvers import reverse
18
from django.forms.utils import flatatt
19
from django.template.loader import render_to_string
20
from django.utils.encoding import force_text
21
from django.utils.html import conditional_escape
22
from django.utils.safestring import mark_safe
23
from django.utils.translation import get_language
24

  
25
import ckeditor.widgets
26

  
27
def ckeditor_render(self, name, value, attrs=None):
28
    if value is None:
29
        value = ''
30
    final_attrs = {'name': name}
31
    if getattr(self, 'attrs', None):
32
        final_attrs.update(self.attrs)
33
    if attrs:
34
        final_attrs.update(attrs)
35
    if 'filebrowserUploadUrl' not in self.config:
36
        self.config.setdefault('filebrowserUploadUrl', reverse('ckeditor_upload'))
37
    if 'filebrowserBrowseUrl' not in self.config:
38
        self.config.setdefault('filebrowserBrowseUrl', reverse('ckeditor_browse'))
39
    if not self.config.get('language'):
40
        self.config['language'] = get_language()
41

  
42
    # Force to text to evaluate possible lazy objects
43
    external_plugin_resources = [[force_text(a), force_text(b), force_text(c)] for a, b, c in self.external_plugin_resources]
44

  
45
    return mark_safe(render_to_string('ckeditor/widget.html', {
46
        'final_attrs': flatatt(final_attrs),
47
        'value': conditional_escape(force_text(value)),
48
        'id': final_attrs['id'],
49
        'config': ckeditor.widgets.json_encode(self.config),
50
        'external_plugin_resources' : ckeditor.widgets.json_encode(external_plugin_resources)
51
    }))
52

  
53
ckeditor.widgets.CKEditorWidget.render = ckeditor_render
0
-