ueditor_settings.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. from django.conf import settings as gSettings # 全局设置
  2. # 工具栏样式,可以添加任意多的模式
  3. toolbars_settings = {
  4. "besttome": [
  5. ['source', 'undo', 'redo', 'bold', 'italic', 'underline', 'forecolor', 'backcolor', 'superscript', 'subscript',
  6. "justifyleft", "justifycenter", "justifyright", "insertorderedlist", "insertunorderedlist", "blockquote",
  7. 'formatmatch', "removeformat", 'autotypeset', 'inserttable', "pasteplain", "wordimage", "searchreplace", "map",
  8. "preview", "fullscreen"],
  9. ['insertcode', 'paragraph', "fontfamily", "fontsize", 'link', 'unlink', 'insertimage', 'insertvideo',
  10. 'attachment', 'emotion', "date", "time"]],
  11. "mini": [['source', '|', 'undo', 'redo', '|', 'bold', 'italic', 'underline', 'formatmatch', 'autotypeset', '|',
  12. 'forecolor', 'backcolor', '|', 'link', 'unlink', '|', 'simpleupload', 'attachment']],
  13. "normal": [['source', '|', 'undo', 'redo', '|', 'bold', 'italic', 'underline', 'removeformat', 'formatmatch',
  14. 'autotypeset', '|', 'forecolor', 'backcolor', '|', 'link', 'unlink', '|', 'simpleupload', 'emotion',
  15. 'attachment', '|', 'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow',
  16. 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows',
  17. 'splittocols']]
  18. }
  19. # 默认的Ueditor设置,请参见ueditor.config.js
  20. ueditor_settings = {
  21. "toolbars": toolbars_settings["normal"],
  22. "autoFloatEnabled": False,
  23. "defaultPathFormat": "%(basename)s_%(datetime)s_%(rnd)s.%(extname)s" # 默认保存上传文件的命名方式
  24. }
  25. # 请参阅php文件夹里面的config.json进行配置
  26. ueditor_upload_settings = {
  27. # 上传图片配置项
  28. "imageActionName": "uploadimage", # 执行上传图片的action名称
  29. "imageMaxSize": 10485760, # 上传大小限制,单位B,10M
  30. "imageFieldName": "upfile", # * 提交的图片表单名称 */
  31. "imagePathFormat": "",
  32. "imageInsertAlign": "none",
  33. "imageAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], # 上传图片格式显示
  34. # 涂鸦图片上传配置项 */
  35. "scrawlActionName": "uploadscrawl", # 执行上传涂鸦的action名称 */
  36. "scrawlFieldName": "upfile", # 提交的图片表单名称 */
  37. "scrawlMaxSize": 10485760, # 上传大小限制,单位B 10M
  38. "scrawlPathFormat": "",
  39. "scrawlInsertAlign": "none",
  40. # 截图工具上传 */
  41. "snapscreenActionName": "uploadimage", # 执行上传截图的action名称 */
  42. "snapscreenPathFormat": "",
  43. "snapscreenInsertAlign": "none", # /* 插入的图片浮动方式 */
  44. # 抓取远程图片配置 */
  45. "catcherLocalDomain": ["127.0.0.1", "localhost", "img.baidu.com"],
  46. "catcherPathFormat": "",
  47. "catcherActionName": "catchimage", # 执行抓取远程图片的action名称 */
  48. "catcherFieldName": "source", # 提交的图片列表表单名称 */
  49. "catcherMaxSize": 10485760, # 上传大小限制,单位B */
  50. "catcherAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], # 抓取图片格式显示 */
  51. "catcherInsertAlign": "none", # /* 插入的图片浮动方式 */
  52. # 上传视频配置 */
  53. "videoActionName": "uploadvideo", # 执行上传视频的action名称 */
  54. "videoPathFormat": "",
  55. "videoFieldName": "upfile", # 提交的视频表单名称 */
  56. "videoMaxSize": 102400000, # 上传大小限制,单位B,默认100MB */
  57. "videoAllowFiles": [
  58. ".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
  59. ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid"], # 上传视频格式显示 */
  60. # 上传文件配置 */
  61. "fileActionName": "uploadfile", # controller里,执行上传视频的action名称 */
  62. "filePathFormat": "",
  63. "fileFieldName": "upfile", # 提交的文件表单名称 */
  64. "fileMaxSize": 204800000, # 上传大小限制,单位B,200MB */
  65. "fileAllowFiles": [
  66. ".png", ".jpg", ".jpeg", ".gif", ".bmp",
  67. ".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
  68. ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid",
  69. ".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso",
  70. ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml"
  71. ], # 上传文件格式显示 */
  72. # 列出指定目录下的图片 */
  73. "imageManagerActionName": "listimage", # 执行图片管理的action名称 */
  74. "imageManagerListPath": "",
  75. "imageManagerListSize": 30, # 每次列出文件数量 */
  76. "imageManagerAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], # 列出的文件类型 */
  77. # 列出指定目录下的文件 */
  78. "fileManagerActionName": "listfile", # 执行文件管理的action名称 */
  79. "fileManagerListPath": "",
  80. "fileManagerListSize": 30, # 每次列出文件数量 */
  81. "fileManagerAllowFiles": [
  82. ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tif", ".psd"
  83. ".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg",
  84. ".mpg",
  85. ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid",
  86. ".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso",
  87. ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml",
  88. ".exe", ".com", ".dll", ".msi"
  89. ] # 列出的文件类型 */
  90. }
  91. # 更新配置:从用户配置文件settings.py重新读入配置UEDITOR_SETTINGS,覆盖默认
  92. def update_user_settings():
  93. user_settings = getattr(gSettings, "UEDITOR_SETTINGS", {}).copy()
  94. if 'config' in user_settings:
  95. ueditor_settings.update(user_settings["config"])
  96. if 'upload' in user_settings:
  97. ueditor_upload_settings.update(user_settings["upload"])
  98. # 读取用户Settings文件并覆盖默认配置
  99. update_user_settings()
  100. # 取得配置项参数
  101. def get_ueditor_settings(key, default=None):
  102. return ueditor_settings.get(key, default)