Commits

Harro van der Klauw committed cbf091b

Added TinyMCE widget

Comments (0)

Files changed (4)

 + requirements for django-cms-2.0
 
 Last tested with:
-- django-cms-2.0: rev 2b59edde3cf1c140edfb14b544f2fbcbd56073f8
+- django-cms-2.0: rev 276bae54e2184187db7e71f2aab54121db7c729d
 - django: 1.1.1
 
 Setup
 - Create the propper templates for your site, the ones included with the app are VERY basic
 
 Todo and Tomaybes:
-- Use the textplugin's way of using a editor for the content (WYMEditor done, still needs tinymce)
 - Add more tests
 - add to cms_plugins.py for plugins
  - month view with days that link to archive_day view
 CMS_NAVIGATION_EXTENDERS = (
     ('cmsplugin_news.navigation.get_nodes','News navigation'),
 )
+
+
+Suggestion:
+To avoid confusion add a "application" template to the CMS which is like other templates but without any placeholders.
+That way users won't get tempted to fill the placeholders and then complain they don't show up ;-)

cmsplugin_news/forms.py

 from django.conf import settings
 
 from cms.plugin_pool import plugin_pool
-
+from cms.plugins.text.settings import USE_TINYMCE
 from cmsplugin_news.widgets.wymeditor_widget import WYMEditor
 
 
         
     def _get_widget(self):
         plugins = plugin_pool.get_text_enabled_plugins(placeholder=None)
-        # if USE_TINYMCE and "tinymce" in settings.INSTALLED_APPS:
-        #             from cms.plugins.text.widgets.tinymce_widget import TinyMCEEditor
-        #             return TinyMCEEditor(installed_plugins=plugins)
-        #         else:
-        return WYMEditor(installed_plugins=plugins)
+        if USE_TINYMCE and "tinymce" in settings.INSTALLED_APPS:
+            from cmsplugin_news.widgets.tinymce_widget import TinyMCEEditor
+            return TinyMCEEditor(installed_plugins=plugins)
+        else:
+            return WYMEditor(installed_plugins=plugins)
         
         
     def __init__(self, *args, **kwargs):

cmsplugin_news/templates/cmsplugin_news/widgets/tinymce.html

+{% load i18n %}
+
+// Global var, for storing callbacks, see below.
+var editPluginPopupCallbacks = {};
+
+{% include "cms/plugins/widgets/widget_lib.js" %}

cmsplugin_news/widgets/tinymce_widget.py

+from tinymce.widgets import TinyMCE, get_language_config
+from cms.settings import CMS_MEDIA_URL
+from django.utils.translation import get_language
+from django.template.loader import render_to_string
+from django.utils.safestring import mark_safe
+from os.path import join
+from django.utils.encoding import smart_unicode
+import tinymce.settings
+from django.utils import simplejson
+from django.template.defaultfilters import escape
+from django.forms.widgets import flatatt
+import cms.plugins.text.settings
+
+class TinyMCEEditor(TinyMCE):
+    
+    def __init__(self, installed_plugins=None,  **kwargs):
+        super(TinyMCEEditor, self).__init__(**kwargs)
+        self.installed_plugins = installed_plugins
+        
+    def render_additions(self, name, value, attrs=None):
+        language = get_language()
+        context = {
+            'name': name,
+            'language': language,
+            'CMS_MEDIA_URL': CMS_MEDIA_URL,
+            'installed_plugins': self.installed_plugins,
+        }
+        return mark_safe(render_to_string(
+            'cmsplugin_news/widgets/tinymce.html', context))
+        
+    def _media(self):
+        media = super(TinyMCEEditor, self)._media()
+        media.add_js([join(CMS_MEDIA_URL, path) for path in (
+                      'js/lib/jquery.js',
+                      )])
+        media.add_css({"all":[join(CMS_MEDIA_URL, path) for path in ('css/jquery/cupertino/jquery-ui.css',
+                                                                     'css/tinymce_toolbar.css')]})
+        
+        return media
+    
+    
+    media = property(_media)
+    
+    def render(self, name, value, attrs=None):
+        if value is None: value = ''
+        value = smart_unicode(value)
+        final_attrs = self.build_attrs(attrs)
+        final_attrs['name'] = name
+        assert 'id' in final_attrs, "TinyMCE widget attributes must contain 'id'"
+        mce_config = cms.plugins.text.settings.TINYMCE_CONFIG.copy()
+        mce_config.update(get_language_config(self.content_language))
+        if tinymce.settings.USE_FILEBROWSER:
+            mce_config['file_browser_callback'] = "djangoFileBrowser"
+        mce_config.update(self.mce_attrs)
+        mce_config['mode'] = 'exact'
+        mce_config['elements'] = final_attrs['id']
+        mce_config['strict_loading_mode'] = 1
+        """
+        plugins = mce_config.get("plugins", "")
+        if len(plugins):
+            plugins += ","
+        plugins += "-cmsplugins"
+        mce_config['plugins'] = plugins
+        adv2 = mce_config.get('theme_advanced_buttons1', "")
+        if len(adv2):
+            adv2 = "," + adv2
+        adv2 = "cmsplugins,cmspluginsedit" + adv2
+        mce_config['theme_advanced_buttons1'] = adv2
+        """
+        json = simplejson.dumps(mce_config)
+        
+        html = [u'<textarea%s>%s</textarea>' % (flatatt(final_attrs), escape(value))]
+        if tinymce.settings.USE_COMPRESSOR:
+            compressor_config = {
+                'plugins': mce_config.get('plugins', ''),
+                'themes': mce_config.get('theme', 'advanced'),
+                'languages': mce_config.get('language', ''),
+                'diskcache': True,
+                'debug': False,
+            }
+            c_json = simplejson.dumps(compressor_config)
+            html.append(u'<script type="text/javascript">tinyMCE_GZ.init(%s);</script>' % (c_json))
+        html.append(u'<script type="text/javascript">%s;\ntinyMCE.init(%s);</script>' % (self.render_additions(name, value, attrs), json))
+        return mark_safe(u'\n'.join(html))
+    
+    
+    
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.