Changes between Initial Version and Version 1 of CookBookAdminTools


Ignore:
Timestamp:
09/15/05 02:25:12 (17 years ago)
Author:
eugene@…
Comment:

initial creation

Legend:

Unmodified
Added
Removed
Modified
  • CookBookAdminTools

    v1 v1  
     1= Admin Tools =
     2
     3== How to Add WYSIWIG Editor ==
     4
     5There are several free WYSIWYG editors, which can be used with Django's admin pages. Some overview and first hand experience can be found [http://lazutkin.com/blog/2005/aug/26/using_tinymce_djangos_admin/ here].
     6
     7=== TinyMCE ===
     8
     9Why TinyMCE? Some reasons are given in [http://www.socialistsoftware.com/?p=8 Django and TinyMCE] and [http://lazutkin.com/blog/2005/aug/26/using_tinymce_djangos_admin/ Using TinyMCE with Django's Admin]. Try [http://tinymce.moxiecode.com/example_full.php?example=true examples].
     10
     11In order to use TinyMCE with Django you have to do three things:
     12
     131. 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.''
     14
     152. Create configuration file for TinyMCE. Below is my '''textareas.js''' file:
     16
     17{{{
     18tinyMCE.init({
     19        mode : "textareas",
     20        theme : "advanced",
     21        //auto_resize : true,
     22        auto_cleanup_word : true,
     23        plugins : "table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,zoom,flash,searchreplace,print,contextmenu,fullscreen",
     24        theme_advanced_buttons1_add_before : "save,separator",
     25        theme_advanced_buttons1_add : "fontselect,fontsizeselect",
     26        theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,zoom,separator,forecolor,backcolor",
     27        theme_advanced_buttons2_add_before: "cut,copy,paste,separator,search,replace,separator",
     28        theme_advanced_buttons3_add_before : "tablecontrols,separator",
     29        theme_advanced_buttons3_add : "fullscreen,emotions,iespell,flash,advhr,separator,print",
     30        theme_advanced_toolbar_location : "top",
     31        theme_advanced_toolbar_align : "left",
     32        theme_advanced_path_location : "bottom",
     33        plugin_insertdate_dateFormat : "%m/%d/%Y",
     34        plugin_insertdate_timeFormat : "%H:%M:%S",
     35        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]",
     36        fullscreen_settings : {
     37                theme_advanced_path_location : "top"
     38        }
     39});
     40}}}
     41
     42I 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 [http://tinymce.moxiecode.com/tinymce/docs/index.html TinyMCE Documentation].
     43
     443. Add '''js''' option to admin sections of your model (excerpt from my model):
     45
     46{{{
     47class Document(meta.Model):
     48    # model fields are here
     49
     50    class META:
     51        admin = meta.Admin(
     52            # various admin options are here
     53            js = (
     54                '/tiny_mce/tiny_mce.js',
     55                '/appmedia/admin/js/textareas.js',
     56            ),
     57        )
     58}}}
     59
     60Basically '''js''' option includes tuple items as !JavaScript files in the header of CRUD pages for this model (see [http://www.djangoproject.com/documentation/model_api/#admin-options 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.
     61
     62That's it.
     63
     64Notes:
     65
     66 * 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.
     67 * If you want to make more room for editing, you can do two things:
     68   * Make textareas bigger: use CSS. See [http://www.djangoproject.com/documentation/admin_css/ Customizing the Django admin interface] for details. Hint: textareas have ids.
     69   * Use [http://tinymce.moxiecode.com/tinymce/docs/option_auto_resize.html experimental auto-resize mode]. I don't use it now because it produced annoying flickering.
     70 * Toolbars flicker when you move cursor (backspace, left/right arrows, and so on). Strange but useable.
     71 * 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.
     72
     73Hints:
     74
     75 * Create your text using conventional WYSIWYG editor with all niceties (e.g., Word) and paste the result to TinyMCE.
     76 * Go to HTML mode to see generated code. You can change it here to make it perfect.
     77
     78=== Xinha ===
     79
     80Download Xinha here: http://xinha.python-hosting.com/. Try [http://xinha.python-hosting.com/wiki/Examples example].
     81
     82See [http://www.socialistsoftware.com/?p=10 Django and Xinha] for details.
Back to Top