Created
October 25, 2013 14:37
-
-
Save sveetch/7155679 to your computer and use it in GitHub Desktop.
Patch for Zinnia to use the Ckeditor in zinnia entry admin. Depend on djangocms-text-ckeditor that depend on DjangoCMS. Tested with : * django-cms = 2.4.2 * djangocms-text-ckeditor = 1.0.10 * django-blog-zinnia = 0.12.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -U 4 -N -r zinnia/admin/entry.py zinnia_patch/admin/entry.py | |
--- zinnia/admin/entry.py 2013-09-10 22:19:42.897479915 +0200 | |
+++ zinnia/admin/entry.py 2013-09-10 21:48:27.336230712 +0200 | |
@@ -323,8 +323,11 @@ | |
'', | |
url(r'^autocomplete_tags/$', | |
self.admin_site.admin_view(self.autocomplete_tags), | |
name='zinnia_entry_autocomplete_tags'), | |
+ url(r'^ckeditor/$', | |
+ self.admin_site.admin_view(self.ckeditor), | |
+ name='zinnia_entry_ckeditor'), | |
url(r'^wymeditor/$', | |
self.admin_site.admin_view(self.wymeditor), | |
name='zinnia_entry_wymeditor'), | |
url(r'^markitup/$', | |
@@ -340,8 +343,26 @@ | |
return TemplateResponse( | |
request, 'admin/zinnia/entry/autocomplete_tags.js', | |
mimetype='application/javascript') | |
+ def ckeditor(self, request): | |
+ """View for serving the config of WYMEditor""" | |
+ import json | |
+ | |
+ language = get_language().split('-')[0] | |
+ | |
+ return TemplateResponse( | |
+ request, 'admin/zinnia/entry/ckeditor.js', | |
+ { | |
+ 'name': "content", | |
+ 'language': language, | |
+ 'settings': language.join(json.dumps(project_settings.CKEDITOR_SETTINGS).split("{{ language }}")), | |
+ 'STATIC_URL': project_settings.STATIC_URL, | |
+ 'installed_plugins': {}, | |
+ 'plugin_pk': None, | |
+ }, | |
+ 'application/javascript') | |
+ | |
def wymeditor(self, request): | |
"""View for serving the config of WYMEditor""" | |
return TemplateResponse( | |
request, 'admin/zinnia/entry/wymeditor.js', | |
@@ -378,8 +399,23 @@ | |
js=('%sjs/wymeditor/jquery.wymeditor.pack.js' % STATIC_URL, | |
'%sjs/wymeditor/plugins/hovertools/' | |
'jquery.wymeditor.hovertools.js' % STATIC_URL, | |
reverse('admin:zinnia_entry_wymeditor'))) | |
+ elif settings.WYSIWYG == 'ckeditor': | |
+ media += Media( | |
+ css={ | |
+ 'all': ( | |
+ '%scss/cms.ckeditor.css' % project_settings.STATIC_URL, | |
+ '%sckeditor/editor.css' % project_settings.STATIC_URL, | |
+ ) | |
+ }, | |
+ js=( | |
+ '%sckeditor/ckeditor.js' % project_settings.STATIC_URL, | |
+ '%sjs/cms.ckeditor.js' % project_settings.STATIC_URL, | |
+ '%sfilebrowser/js/FB_CKEditor.js' % project_settings.STATIC_URL, | |
+ reverse('admin:zinnia_entry_ckeditor') | |
+ ) | |
+ ) | |
elif settings.WYSIWYG == 'tinymce': | |
from tinymce.widgets import TinyMCE | |
media += TinyMCE().media + Media( | |
js=(reverse('tinymce-js', args=('admin/zinnia/entry',)),)) | |
diff -U 4 -N -r zinnia/templates/admin/zinnia/entry/ckeditor.js zinnia_patch/templates/admin/zinnia/entry/ckeditor.js | |
--- zinnia/templates/admin/zinnia/entry/ckeditor.js 1970-01-01 01:00:00.000000000 +0100 | |
+++ zinnia/templates/admin/zinnia/entry/ckeditor.js 2013-09-10 04:00:40.338711549 +0200 | |
@@ -0,0 +1,36 @@ | |
+{% load i18n %} | |
+$(document).ready(function() { | |
+ // get the container id | |
+ var container = 'id_{{ name }}'; | |
+ var prefixPos = container.indexOf('-__prefix__'); | |
+ if (prefixPos != - 1) { | |
+ // in case the textarea is in an inline, we need to perform some replacements | |
+ var name = container.substring(0, prefixPos); | |
+ var replacement = $('#' + name + "-TOTAL_FORMS").val(); | |
+ container = container.replace('__prefix__', replacement); | |
+ } | |
+ | |
+ // initialize ckeditor only if the container exists | |
+ if ($('#'+container).length > 0) { | |
+ CMS.CKEditor.init(container, {{ settings|safe }}, { | |
+ 'static_url': '{{ STATIC_URL }}', | |
+ 'page': '{{ plugin_pk }}', | |
+ 'lang': { | |
+ 'toolbar': '{% filter escapejs %}{% trans "CMS Plugins" %}{% endfilter %}', | |
+ 'add': '{% filter escapejs %}{% trans "Add CMS Plugin" %}{% endfilter %}', | |
+ 'edit': '{% filter escapejs %}{% trans "Edit CMS Plugin" %}{% endfilter %}', | |
+ 'aria': '{% filter escapejs %}{% trans "CMS Plugins" %}{% endfilter %}' | |
+ }, | |
+ 'plugins': [ | |
+ {% regroup installed_plugins by module as module_list %} | |
+ {% for module in module_list %} | |
+ { group: '{% filter escapejs %}{% if module.grouper %}{{ module.grouper|capfirst }}{% else %}{% trans "Standard Plugins" %}{% endif %}{% endfilter %}', items: [ | |
+ {% for plugin in module.list %} | |
+ { 'title': '{% filter escapejs %}{{ plugin.name }}{% endfilter %}', 'type': '{% filter escapejs %}{{ plugin.value }}{% endfilter %}' }{% if not forloop.las %},{% endif %} | |
+ {% endfor %} | |
+ ]}{% if not forloop.las %},{% endif %} | |
+ {% endfor %} | |
+ ] | |
+ }); | |
+ } | |
+}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Enable ckeditor usage for entries editor | |
ZINNIA_WYSIWYG = "ckeditor" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment