Version 1 (modified by eugene@…, 19 years ago) ( diff )

initial creation

Admin Tools

How to Add WYSIWIG Editor

There are several free WYSIWYG editors, which can be used with Django's admin pages. Some overview and first hand experience can be found here.

TinyMCE

Why TinyMCE? Some reasons are given in Django and TinyMCE and Using TinyMCE with Django's Admin. Try examples.

In order to use TinyMCE with Django you have to do three things:

  1. Go to http://tinymce.moxiecode.com/ and download TinyMCE. Install it somewhere on your web server. It's better to serve it directly bypassing Django machinery. Optional: download TinyMCE compressor. You can use it, if your server supports PHP.
  1. Create configuration file for TinyMCE. Below is my textareas.js file:
tinyMCE.init({
	mode : "textareas",
	theme : "advanced",
	//auto_resize : true,
	auto_cleanup_word : true,
	plugins : "table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,zoom,flash,searchreplace,print,contextmenu,fullscreen",
	theme_advanced_buttons1_add_before : "save,separator",
	theme_advanced_buttons1_add : "fontselect,fontsizeselect",
	theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,zoom,separator,forecolor,backcolor",
	theme_advanced_buttons2_add_before: "cut,copy,paste,separator,search,replace,separator",
	theme_advanced_buttons3_add_before : "tablecontrols,separator",
	theme_advanced_buttons3_add : "fullscreen,emotions,iespell,flash,advhr,separator,print",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_path_location : "bottom",
	plugin_insertdate_dateFormat : "%m/%d/%Y",
	plugin_insertdate_timeFormat : "%H:%M:%S",
	extended_valid_elements : "a[name|href|target=_blank|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
	fullscreen_settings : {
		theme_advanced_path_location : "top"
	}
});

I use advanced theme, and practically all standard plugins, which don't require server support. Mode "textareas" instructs TinyMCE to convert all textareas to WYSIWYG editors. You can look up all options in TinyMCE Documentation.

  1. Add js option to admin sections of your model (excerpt from my model):
class Document(meta.Model):
    # model fields are here

    class META:
        admin = meta.Admin(
            # various admin options are here
            js = (
                '/tiny_mce/tiny_mce.js',
                '/appmedia/admin/js/textareas.js',
            ),
        )

Basically js option includes tuple items as JavaScript files in the header of CRUD pages for this model (see Django Model Reference / Admin Options). The first script is the main TinyMCE file. If you use TinyMCE compressor, include '/tiny_mce/tiny_mce_gzip.php' instead. The second script is your configuration file created in step #2.

That's it.

Notes:

  • TinyMCE toolbars will occupy almost all area of textarea. I don't mind, because when I want to edit text, I use full screen mode. It's a button on toolbar looking like a monitor.
  • If you want to make more room for editing, you can do two things:
  • Toolbars flicker when you move cursor (backspace, left/right arrows, and so on). Strange but useable.
  • I wish I could have specify different set of tools for inline and full screen modes. It may be possible, but I didn't research it yet.

Hints:

  • Create your text using conventional WYSIWYG editor with all niceties (e.g., Word) and paste the result to TinyMCE.
  • Go to HTML mode to see generated code. You can change it here to make it perfect.

Xinha

Download Xinha here: http://xinha.python-hosting.com/. Try example.

See Django and Xinha for details.

Note: See TracWiki for help on using the wiki.
Back to Top