fromos.pathimportjoinfromdjango.utils.safestringimportmark_safefromdjango.template.loaderimportrender_to_stringfromdjango.formsimportTextareafromcms.settingsimportCMS_MEDIA_URLfromcms.plugins.textimportsettingsastext_settingsfromdjango.utils.translation.trans_realimportget_languageclassWYMEditor(Textarea):classMedia:js=[join(CMS_MEDIA_URL,path)forpathin('js/lib/jquery.js','wymeditor/jquery.wymeditor.js','wymeditor/plugins/resizable/jquery.wymeditor.resizable.js',)]def__init__(self,attrs=None,installed_plugins=None):""" Create a widget for editing text + plugins. installed_plugins is a list of plugins to display that are text_enabled """self.attrs={'class':'wymeditor'}ifattrs:self.attrs.update(attrs)super(WYMEditor,self).__init__(attrs)self.installed_plugins=installed_pluginsdefrender_textarea(self,name,value,attrs=None):returnsuper(WYMEditor,self).render(name,value,attrs)defrender_additions(self,name,value,attrs=None):language=get_language()context={'name':name,'language':language,'CMS_MEDIA_URL':CMS_MEDIA_URL,'WYM_TOOLS':mark_safe(text_settings.WYM_TOOLS),'WYM_CONTAINERS':mark_safe(text_settings.WYM_CONTAINERS),'WYM_CLASSES':mark_safe(text_settings.WYM_CLASSES),'WYM_STYLES':mark_safe(text_settings.WYM_STYLES),'WYM_STYLESHEET':mark_safe(text_settings.WYM_STYLESHEET),'installed_plugins':self.installed_plugins,}returnmark_safe(render_to_string('cmsplugin_news/widgets/wymeditor.html',context))defrender(self,name,value,attrs=None):returnself.render_textarea(name,value,attrs)+ \
self.render_additions(name,value,attrs)