管理员字段无法在django中使用tinymce和filebrowser进行保存

时间:2010-07-12 19:09:43

标签: django django-admin tinymce django-tinymce django-filebrowser

我正在使用django-tinymce和运行django 1.2的django-filebrowser的no grappelli分支。

我将tinymce HTMLField模型定义用于我希望WYSIWYG的模型字段。

我已经将正确的javascript添加到我的AdminModel中,并且文件浏览器工作得很好,将图像添加到textarea没有问题,但是,当我保存时,textarea不会更新(看起来像tinnymce不会触摸它什么时候应该)。当我关闭filebrowser插件时,一切正常,所以必须与它和TinyMCE onSubmit功能发生冲突。

我一直在弄乱它并且无法到达任何地方 - 所有这些对我来说都是新鲜的,所以即使是一些混乱的想法也会有所帮助。

提前致谢。

编辑:添加了奖励信息 - “模式”配置中的默认模式为“textareas”。当我删除它时,一切都正确保存。可悲的是,这也删除了我正在做的所有这一切的图像按钮......

更新

以下是我使用的TinyMCE配置(django-filebrowser附带的配置 - 已损坏):

tinyMCE.init({
  mode: "textareas", 
  theme: "advanced",
  language: "en",
  skin: "o2k7",
  browsers: "gecko",
  dialog_type: "modal",
  object_resizing: true,
  cleanup_on_startup: true,
  forced_root_block: "p",
  remove_trailing_nbsp: true,
  theme_advanced_toolbar_location: "top",
  theme_advanced_toolbar_align: "left",
  theme_advanced_statusbar_location: "none",
  theme_advanced_buttons1: "formatselect,bold,italic,underline,bullist,numlist,undo,redo,link,unlink,image,code,fullscreen,pasteword,media,charmap",
  theme_advanced_buttons2: "",
  theme_advanced_buttons3: "",
  theme_advanced_path: false,
  theme_advanced_blockformats: "p,h2,h3,h4,h5,h6",
  width: '700',
  height: '200',
  plugins: "advimage,advlink,fullscreen,visualchars,paste,media,template,searchreplace",
  advimage_styles: "Linksbündig neben Text=img_left;Rechtsbündig neben Text=img_right;Eigener Block=img_block",
  advlink_styles: "internal (sehmaschine.net)=internal;external (link to an external site)=external",
  advimage_update_dimensions_onchange: true,
  file_browser_callback: "CustomFileBrowser",
  relative_urls: false,
  valid_elements : "" +
  "-p," + 
  "a[href|target=_blank|class]," +
  "-strong/-b," +
  "-em/-i," +
  "-u," + 
  "-ol," + 
  "-ul," + 
  "-li," + 
  "br," + 
  "img[class|src|alt=|width|height]," + 
  "-h2,-h3,-h4," + 
  "-pre," +
  "-code," + 
  "-div",
  extended_valid_elements: "" + 
  "a[name|class|href|target|title|onclick]," + 
     img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name]," + 
  "br[clearfix]," + 
  "-p[class<clearfix?summary?code]," + 
  "h2[class<clearfix],h3[class<clearfix],h4[class<clearfix]," + 
  "ul[class<clearfix],ol[class<clearfix]," + 
  "div[class],"
});

这是我遇到的两个问题之一 - 也将在下面发布答案。

1 个答案:

答案 0 :(得分:3)

问题实际上是双重的。第一个问题是django-filebrowser-no-grappelli附带的默认TinyMCE配置(上面的问题)。我不确定它有什么问题,但是当按下提交按钮时,它阻止了实际的表单字段的更新。

当我使用TinyMCE的自定义配置时,表单字段保存工作正常,但文件浏览已损坏。这是因为如果django-tinymce在安装的应用程序列表中看到'filebrowser',它会覆盖file_browser_callback并将其设置为'djangoFileBrowser',所以即使我在我自己的配置中将其正确设置为'CustomFileBrowser'也是如此。解决方案是明确告诉它不要设置该值。我添加了以下settings.py:

TINYMCE_DEFAULT_CONFIG = {
    'theme': 'advanced',
    'theme_advanced_toolbar_location': "top",
    'theme_advanced_toolbar_align': "left",
    'skin': "o2k7",
    "file_browser_callback" : "CustomFileBrowser",
}
TINYMCE_FILEBROWSER = False

一切似乎都运转正常。这个问题似乎与我的版本组合相当独特。