settings.py 6.0 KB

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