From 57c0e857b3f8fe23f70b17420e1ab409e4de1a8b Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Wed, 11 Nov 2020 19:47:14 +0100 Subject: [PATCH] reduce CKEditor plugins --- dev-scripts/ckeditor_info.py | 42 +++++++++ inventory_project/settings/base.py | 138 ++++++++++++++++++++++++----- 2 files changed, 156 insertions(+), 24 deletions(-) create mode 100644 dev-scripts/ckeditor_info.py diff --git a/dev-scripts/ckeditor_info.py b/dev-scripts/ckeditor_info.py new file mode 100644 index 0000000..4e2c109 --- /dev/null +++ b/dev-scripts/ckeditor_info.py @@ -0,0 +1,42 @@ +""" + Helpter +""" + +from pathlib import Path + +import ckeditor + + +ckeditor_path = Path(ckeditor.__file__).parent +print('Django-CKEditor path:', ckeditor_path) + +build_config_path = Path(ckeditor_path, 'static/ckeditor/ckeditor/build-config.js') +print('Build config:', build_config_path) + +plugins_path = Path(ckeditor_path, 'static/ckeditor/ckeditor/plugins') +print('Plugin path:', plugins_path) + +assert plugins_path.is_dir() + +plugins = set(item.name for item in plugins_path.iterdir() if item.is_dir()) + +in_plugins = False +with build_config_path.open('r') as f: + for line in f: + line = line.strip() + if not line: + continue + if line == 'plugins : {': + in_plugins = True + continue + + if in_plugins: + if line == '},': + break + plugin_name = line.split(':',1)[0].strip(" '") + plugins.add(plugin_name) + +print("'removePlugins': (") +for plugin_name in sorted(plugins): + print(f" '{plugin_name}',") +print(')') diff --git a/inventory_project/settings/base.py b/inventory_project/settings/base.py index 053efd0..3ec36e5 100644 --- a/inventory_project/settings/base.py +++ b/inventory_project/settings/base.py @@ -142,31 +142,121 @@ DBBACKUP_STORAGE_OPTIONS = {'location': str(__Path(BASE_PATH, 'backups'))} CKEDITOR_BASEPATH = STATIC_URL + 'ckeditor/ckeditor/' CKEDITOR_FILENAME_GENERATOR = 'inventory.ckeditor_upload.get_filename' +CKEDITOR_DEFAULT_CONFIG = { + 'skin': 'moono-lisa', + 'removeButtons': 'Language,Cut,Copy,Paste,Undo,Redo,Anchor', + + # plugins are here: .../site-packages/ckeditor/static/ckeditor/ckeditor/plugins + # and here: https://github.com/ckeditor/ckeditor4/tree/major/plugins + # See also: .../site-packages/ckeditor/static/ckeditor/ckeditor/build-config.js + 'removePlugins': ( + # Generated with .../dev-scripts/ckeditor_info.py + 'a11yhelp', + 'about', + 'adobeair', + 'ajax', + 'autoembed', + # 'autogrow', + 'autolink', + # 'basicstyles', + 'bbcode', + 'bidi', + # 'blockquote', + 'clipboard', + 'codesnippet', + 'codesnippetgeshi', + # 'colorbutton', + # 'colordialog', + 'contextmenu', + 'copyformatting', + 'devtools', + 'dialog', + 'dialogadvtab', + 'div', + 'divarea', + 'docprops', + # 'elementspath', + 'embed', + 'embedbase', + 'embedsemantic', + 'enterkey', + # 'entities', + # 'filebrowser', + # 'filetools', + 'find', + 'flash', + # 'floatingspace', + # 'font', + # 'format', + 'forms', + # 'horizontalrule', + 'htmlwriter', + 'iframe', + 'iframedialog', + # 'image', + # 'image2', + # 'indentblock', + # 'indentlist', + # 'justify', + 'language', + # 'lineutils', + # 'link', + # 'list', + # 'liststyle', + 'magicline', + 'mathjax', + # 'maximize', + # 'menubutton', + 'newpage', + 'notification', + 'notificationaggregator', + 'pagebreak', + 'pastefromgdocs', + 'pastefromword', + 'pastetext', + 'pastetools', + 'placeholder', + 'preview', + 'print', + # 'removeformat', + # 'resize', + 'save', + 'scayt', + 'selectall', + 'sharedspace', + # 'showblocks', + # 'showborders', + 'smiley', + 'sourcearea', + 'sourcedialog', + 'specialchar', + 'stylescombo', + 'stylesheetparser', + 'tab', + # 'table', + # 'tableresize', + # 'tableselection', + # 'tabletools', + 'templates', + # 'toolbar', + 'uicolor', + # 'undo', + # 'uploadimage', + # 'uploadwidget', + 'widget', + 'wsc', + # 'wysiwygarea', + 'xml', + ), + 'toolbar': 'full', + 'height': '25em', + 'width': '100%', + 'filebrowserWindowWidth': 940, + 'filebrowserWindowHeight': 725, +} CKEDITOR_CONFIGS = { - 'ItemModel.description': { - 'skin': 'moono-lisa', - 'removeButtons': 'Language', - - # plugins are here: site-packages/ckeditor/static/ckeditor/ckeditor/plugins - 'removePlugins': 'wsc,div,flash,iframe,bidi', - 'toolbar': 'full', - 'height': '25em', - 'width': '100%', - 'filebrowserWindowWidth': 940, - 'filebrowserWindowHeight': 725, - }, - 'LocationModel.description': { - 'skin': 'moono-lisa', - 'removeButtons': 'Language', - - # plugins are here: site-packages/ckeditor/static/ckeditor/ckeditor/plugins - 'removePlugins': 'wsc,div,flash,iframe,bidi', - 'toolbar': 'full', - 'height': '25em', - 'width': '100%', - 'filebrowserWindowWidth': 940, - 'filebrowserWindowHeight': 725, - } + 'ItemModel.description': CKEDITOR_DEFAULT_CONFIG, + 'LocationModel.description': CKEDITOR_DEFAULT_CONFIG } CKEDITOR_RESTRICT_BY_USER = True CKEDITOR_RESTRICT_BY_DATE = True