Skip to content

Instantly share code, notes, and snippets.

@gijs
Created October 27, 2010 14:22
Show Gist options
  • Save gijs/649117 to your computer and use it in GitHub Desktop.
Save gijs/649117 to your computer and use it in GitHub Desktop.
Ugly solution to get jQuery, django-cms, WYMEditor and the Django admin to work together without modifying django-cms' source.
from django import forms
from django.conf import settings
from cms.plugin_pool import plugin_pool
from cms.plugins.text.widgets.wymeditor_widget import WYMEditor
from cmsapp_news.models import NewsItem
class NewsForm(forms.ModelForm):
"""
Defines a form for News model.
"""
# This injects the Django Admin's non-minified jQuery into the WYMEditor's
# JS include list at runtime. By default, the minified version was used,
# which gave errors because jQuery ran in noConflict mode, which in turn
# conflicted with WYMEditor requiring the dollar notation to work.
WYMEditor.Media.js.insert(0, '/static_media/admin/js/jquery.js')
class Meta:
model = NewsItem
def _get_widget(self):
plugins = plugin_pool.get_text_enabled_plugins(placeholder=None,
page=None)
return WYMEditor(installed_plugins=plugins)
def __init__(self, *args, **kwargs):
super(NewsForm, self).__init__(*args, **kwargs)
widget = self._get_widget()
self.fields['article'].widget = widget
@losingle
Copy link

the url request "/add-plugin/" 404 not found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment