Projet

Général

Profil

0001-adapt-ckeditor-inclusion-for-Django-1.11-20959.patch

Serghei Mihai, 05 janvier 2018 10:17

Télécharger (6,39 ko)

Voir les différences:

Subject: [PATCH] adapt ckeditor inclusion for Django 1.11 (#20959)

 corbo/__init__.py    | 20 ++++++++++++++++++++
 corbo/apps.py        | 23 +++++++++++++++++++++++
 corbo/monkeypatch.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 corbo/urls.py        | 10 +++++++++-
 4 files changed, 103 insertions(+), 1 deletion(-)
 create mode 100644 corbo/apps.py
 create mode 100644 corbo/monkeypatch.py
corbo/__init__.py
1
# corbo - Announces Manager
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

  
18
import corbo.monkeypatch
19

  
20
default_app_config = 'corbo.apps.ManagerAppConfig'
corbo/apps.py
1
# corbo - Announces Manager
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.apps import AppConfig
18

  
19
class ManagerAppConfig(AppConfig):
20
    name = 'corbo'
21

  
22
    def ready(self):
23
        import corbo.monkeypatch
corbo/monkeypatch.py
1
# corbo - Announces Manager
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 attrs:
32
        final_attrs.update(attrs)
33
    if 'filebrowserUploadUrl' not in self.config:
34
        self.config.setdefault('filebrowserUploadUrl', reverse('ckeditor_upload'))
35
    if 'filebrowserBrowseUrl' not in self.config:
36
        self.config.setdefault('filebrowserBrowseUrl', reverse('ckeditor_browse'))
37
    if not self.config.get('language'):
38
        self.config['language'] = get_language()
39

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

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

  
51
ckeditor.widgets.CKEditorWidget.render = ckeditor_render
corbo/urls.py
4 4
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
5 5
from django.contrib import admin
6 6

  
7
from django.views.decorators.cache import never_cache
8
from django.contrib.admin.views.decorators import staff_member_required
9

  
7 10
from .urls_utils import decorated_includes, manager_required
8 11
from .views import homepage, atom, unsubscribe, unsubscription_done, login, logout
9 12

  
10 13
from manage_urls import urlpatterns as manage_urls
11 14
from api_urls import urlpatterns as api_urls
12 15

  
16
import ckeditor.views as ckeditor_views
17

  
13 18
urlpatterns = patterns('',
14 19
    url(r'^$', homepage, name='home'),
15 20
    url(r'^atom$', atom, name='atom'),
16 21
    url(r'^manage/', decorated_includes(manager_required,
17 22
                    include(manage_urls))),
18
    url(r'^ckeditor/', include('ckeditor.urls')),
19 23
    url(r'^admin/', include(admin.site.urls)),
20 24
    url(r'^api/', include(api_urls)),
21 25
    url(r'^unsubscribe/done/$', unsubscription_done,
......
24 28
        name='unsubscribe'),
25 29
    url(r'^logout/$', logout, name='auth_logout'),
26 30
    url(r'^login/$', login, name='auth_login'),
31
    url(r'^ckeditor/upload/', staff_member_required(ckeditor_views.upload),
32
        name='ckeditor_upload'),
33
    url(r'^ckeditor/browse/', never_cache(staff_member_required(ckeditor_views.browse)),
34
         name='ckeditor_browse'),
27 35
)
28 36

  
29 37
if 'mellon' in settings.INSTALLED_APPS:
30
-