Changes between Version 2 and Version 3 of RichTextField


Ignore:
Timestamp:
04/21/06 07:03:44 (9 years ago)
Author:
[530]
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • RichTextField

    v2 v3  
    1 A attempt at intergrating tinymce
     1
     2= RichTextField =
     3
     4A attempt at intergrating tinymce completely as a own field
     5
     6
     7== Adding the field type ==
    28
    39project_dir/local_models.py
     
    1925            self.maxlength = maxlength
    2026
     27        # should be able to add the admin js here somehow
     28
     29
    2130    def render(self, data):
    2231        if data is None:
    2332            data = ''
    2433        if isinstance(data, unicode):
    25             data = data.encode(settings.DEFAULT_CHARSET) # add a class to activate editor via editor_selector
     34            data = data.encode(settings.DEFAULT_CHARSET)
     35
     36        # adds a class to activate editor via editor_selector
     37
    2638        return '<textarea id="%s" class="v%s%s mceEditor" name="%s" rows="%s" cols="%s">%s</textarea>' % \
    2739            (self.get_id(), self.__class__.__name__, self.is_required and ' required' or '',
     
    3547}}}
    3648
     49== Adding the neccesary javascript ==
     50
     51/media/js/tmce.js
     52
     53{{{
     54        tinyMCE.init({
     55                mode : "specific_textareas", // only specific textareas
     56                editor_selector : "mceEditor", // specified by the mceEditor class
     57                theme : "advanced",
     58                plugins : "table,save,advhr,advimage,advlink",
     59                theme_advanced_buttons1 : "bold,italic,underline,strikethrough,sub,sup,removeformat,charmap,separator,justifyleft,justifycenter,justifyright,bullist,numlist,outdent,indent,separator,formatselect,styleselect,code",
     60        theme_advanced_buttons2 : "cut,copy,paste,separator,search,replace,image,link,anchor,separator,tablecontrols",
     61                theme_advanced_buttons3 : "",
     62                theme_advanced_toolbar_location : "top",
     63                theme_advanced_toolbar_align : "left",
     64                theme_advanced_path_location : "bottom",
     65                theme_advanced_styles : "Left=left;Right=right;",
     66        content_css : "/media/js/tmce.css",
     67            plugin_insertdate_dateFormat : "%Y-%m-%d",
     68            plugin_insertdate_timeFormat : "%H:%M:%S",
     69                extended_valid_elements : "a[name|href|target|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]",
     70        width : "640", height : "350" // set size of field
     71        });
     72
     73}}}
     74
     75
     76== Using the field in the model ==
    3777
    3878project_dir/appdir/models.py
     
    5393       
    5494    class Admin:
    55         js=['../js/tinymce/jscripts/tiny_mce/tiny_mce.js', '../js/tmce.js'] # this should be added automatically somehow, but only once, not per field
     95        js=['../js/tinymce/jscripts/tiny_mce/tiny_mce.js', '../js/tmce.js']
     96       # this should be added automatically by the field somehow, but only once, not per field instance
    5697
    5798}}}
    58 
    59 And then some javascript
    60 
    61 /media/js/tmce.js
    62 
    63 {{{
    64         tinyMCE.init({
    65                 mode : "specific_textareas",
    66         editor_selector : "mceEditor",
    67                 theme : "advanced",
    68                 plugins : "table,save,advhr,advimage,advlink",
    69                 theme_advanced_buttons1 : "bold,italic,underline,strikethrough,sub,sup,removeformat,charmap,separator,justifyleft,justifycenter,justifyright,bullist,numlist,outdent,indent,separator,formatselect,styleselect,code",
    70         theme_advanced_buttons2 : "cut,copy,paste,separator,search,replace,image,link,anchor,separator,tablecontrols",
    71                 theme_advanced_buttons3 : "",
    72                 theme_advanced_toolbar_location : "top",
    73                 theme_advanced_toolbar_align : "left",
    74                 theme_advanced_path_location : "bottom",
    75                 theme_advanced_styles : "Left=left;Right=right;",
    76         content_css : "/media/js/tmce.css",
    77             plugin_insertdate_dateFormat : "%Y-%m-%d",
    78             plugin_insertdate_timeFormat : "%H:%M:%S",
    79                 extended_valid_elements : "a[name|href|target|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]",
    80         width : "640", height : "350"
    81         });
    82 
    83 }}}
    84 
Back to Top