Skip to content

Commit

Permalink
Merge pull request #141 from hvlads/version_0.2.8
Browse files Browse the repository at this point in the history
Refactor DEFAULT_FILE_STORAGE to STORAGES["default"] (Issue #138)
  • Loading branch information
hvlads authored Jun 4, 2023
2 parents bc84f0d + 81977da commit e6e2e96
Show file tree
Hide file tree
Showing 16 changed files with 468 additions and 3,682 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/lint_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ jobs:
- run: isort --check-only .
- run: pip install --editable .
- run: mypy --non-interactive .
- run: pytest .
- run: cp -R django_ckeditor_5 example/blog
- run: cd example
- run: pip install -e ".[dev]"
- run: pytest example/blog
- run: shopt -s globstar && pyupgrade --py37-plus **/*.py
- run: safety check
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ example/blog/static/*
example/blog/media/*
example/django_ckeditor_5
example/blog/django_ckeditor_5
example/.coverage
example/blog/.coverage
example/blog/tests/.coverage
example/blog/coverage.xml
example/coverage.xml
example/blog/pyproject.toml
django_ckeditor_5/static/django_ckeditor_5/dist/*.map
django_ckeditor_5/static/django_ckeditor_5/dist
Expand Down
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ Includes the following ckeditor5 plugins:
GeneralHtmlSupport,
ImageInsert,
WordCount,
Mention
Mention,
Style


Examples
Expand Down
524 changes: 277 additions & 247 deletions django_ckeditor_5/package-lock.json

Large diffs are not rendered by default.

67 changes: 34 additions & 33 deletions django_ckeditor_5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,48 @@
"author": "",
"license": "ISC",
"dependencies": {
"@ckeditor/ckeditor5-adapter-ckfinder": "^37.1.0",
"@ckeditor/ckeditor5-alignment": "^37.1.0",
"@ckeditor/ckeditor5-autoformat": "^37.1.0",
"@ckeditor/ckeditor5-basic-styles": "^37.1.0",
"@ckeditor/ckeditor5-block-quote": "^37.1.0",
"@ckeditor/ckeditor5-code-block": "^37.1.0",
"@ckeditor/ckeditor5-editor-classic": "^37.1.0",
"@ckeditor/ckeditor5-essentials": "^37.1.0",
"@ckeditor/ckeditor5-font": "^37.1.0",
"@ckeditor/ckeditor5-heading": "^37.1.0",
"@ckeditor/ckeditor5-highlight": "^37.1.0",
"@ckeditor/ckeditor5-html-support": "^37.1.0",
"@ckeditor/ckeditor5-image": "^37.1.0",
"@ckeditor/ckeditor5-indent": "^37.1.0",
"@ckeditor/ckeditor5-adapter-ckfinder": "^38.0.1",
"@ckeditor/ckeditor5-alignment": "^38.0.1",
"@ckeditor/ckeditor5-autoformat": "^38.0.1",
"@ckeditor/ckeditor5-basic-styles": "^38.0.1",
"@ckeditor/ckeditor5-block-quote": "^38.0.1",
"@ckeditor/ckeditor5-code-block": "^38.0.1",
"@ckeditor/ckeditor5-editor-classic": "^38.0.1",
"@ckeditor/ckeditor5-essentials": "^38.0.1",
"@ckeditor/ckeditor5-font": "^38.0.1",
"@ckeditor/ckeditor5-heading": "^38.0.1",
"@ckeditor/ckeditor5-highlight": "^38.0.1",
"@ckeditor/ckeditor5-html-support": "^38.0.1",
"@ckeditor/ckeditor5-image": "^38.0.1",
"@ckeditor/ckeditor5-indent": "^38.0.1",
"@ckeditor/ckeditor5-inspector": "^4.1.0",
"@ckeditor/ckeditor5-link": "^37.1.0",
"@ckeditor/ckeditor5-list": "^37.1.0",
"@ckeditor/ckeditor5-markdown-gfm": "^37.1.0",
"@ckeditor/ckeditor5-media-embed": "^37.1.0",
"@ckeditor/ckeditor5-mention": "^37.1.0",
"@ckeditor/ckeditor5-paragraph": "^37.1.0",
"@ckeditor/ckeditor5-paste-from-office": "^37.1.0",
"@ckeditor/ckeditor5-remove-format": "^37.1.0",
"@ckeditor/ckeditor5-source-editing": "^37.1.0",
"@ckeditor/ckeditor5-table": "^37.1.0",
"@ckeditor/ckeditor5-theme-lark": "^37.1.0",
"@ckeditor/ckeditor5-ui": "^37.1.0",
"@ckeditor/ckeditor5-upload": "^37.1.0",
"@ckeditor/ckeditor5-word-count": "^37.1.0"
"@ckeditor/ckeditor5-link": "^38.0.1",
"@ckeditor/ckeditor5-list": "^38.0.1",
"@ckeditor/ckeditor5-markdown-gfm": "^38.0.1",
"@ckeditor/ckeditor5-media-embed": "^38.0.1",
"@ckeditor/ckeditor5-mention": "^38.0.1",
"@ckeditor/ckeditor5-paragraph": "^38.0.1",
"@ckeditor/ckeditor5-paste-from-office": "^38.0.1",
"@ckeditor/ckeditor5-remove-format": "^38.0.1",
"@ckeditor/ckeditor5-source-editing": "^38.0.1",
"@ckeditor/ckeditor5-style": "^38.0.1",
"@ckeditor/ckeditor5-table": "^38.0.1",
"@ckeditor/ckeditor5-theme-lark": "^38.0.1",
"@ckeditor/ckeditor5-ui": "^38.0.1",
"@ckeditor/ckeditor5-upload": "^38.0.1",
"@ckeditor/ckeditor5-word-count": "^38.0.1"
},
"devDependencies": {
"@ckeditor/ckeditor5-core": "^37.1.0",
"@ckeditor/ckeditor5-dev-utils": "^37.0.1",
"@ckeditor/ckeditor5-core": "^38.0.1",
"@ckeditor/ckeditor5-dev-utils": "^38.0.0",
"@ckeditor/ckeditor5-dev-webpack-plugin": "^31.1.13",
"@ckeditor/ckeditor5-theme-lark": "^37.1.0",
"@ckeditor/ckeditor5-theme-lark": "^38.0.1",
"css-loader": "6",
"mini-css-extract-plugin": "^2.7.5",
"mini-css-extract-plugin": "^2.7.6",
"postcss-loader": "7",
"raw-loader": "4",
"style-loader": "3",
"terser-webpack-plugin": "^5.3.8",
"terser-webpack-plugin": "^5.3.9",
"webpack": "5",
"webpack-cli": "5"
}
Expand Down
14 changes: 8 additions & 6 deletions django_ckeditor_5/static/django_ckeditor_5/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function createEditors() {
const allEditors = document.querySelectorAll('.django_ckeditor_5');
for (let i = 0; i < allEditors.length; ++i) {
const script_id = `${allEditors[i].id}_script`;
if (editorsIds.indexOf(script_id) !== -1){
if (editorsIds.indexOf(script_id) !== -1) {
continue;
}
allEditors[i].nextSibling.remove();
Expand Down Expand Up @@ -53,10 +53,12 @@ function createEditors() {
allEditors[i],
config
).then(editor => {
const wordCountPlugin = editor.plugins.get('WordCount');
const wordCountWrapper = document.getElementById(`word-count-${script_id}`);
wordCountWrapper.innerHTML = '';
wordCountWrapper.appendChild(wordCountPlugin.wordCountContainer);
if (editor.plugins.has('WordCount')) {
const wordCountPlugin = editor.plugins.get('WordCount');
const wordCountWrapper = document.getElementById(`word-count-${script_id}`);
wordCountWrapper.innerHTML = '';
wordCountWrapper.appendChild(wordCountPlugin.wordCountContainer);
}
editors.push(editor);
}).catch(error => {
console.error((error));
Expand All @@ -70,7 +72,7 @@ function createEditors() {
document.addEventListener("DOMContentLoaded", () => {
createEditors();
if (typeof django === "object" && django.jQuery) {
django.jQuery(document).on("formset:added", createEditors);
django.jQuery(document).on("formset:added", createEditors);
}
});

2 changes: 2 additions & 0 deletions django_ckeditor_5/static/django_ckeditor_5/src/ckeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import ImageInsert from '@ckeditor/ckeditor5-image/src/imageinsert';
import {TableCaption} from "@ckeditor/ckeditor5-table";
import WordCount from '@ckeditor/ckeditor5-word-count/src/wordcount';
import Mention from '@ckeditor/ckeditor5-mention/src/mention';
import { Style } from '@ckeditor/ckeditor5-style';

export default class ClassicEditor extends ClassicEditorBase {
}
Expand Down Expand Up @@ -87,4 +88,5 @@ ClassicEditor.builtinPlugins = [
ImageInsert,
WordCount,
Mention,
Style,
];
24 changes: 21 additions & 3 deletions django_ckeditor_5/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.utils.translation import ugettext_lazy as _

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.http import JsonResponse
from PIL import Image

Expand All @@ -19,9 +20,26 @@ class NoImageException(Exception):


def get_storage_class():
if hasattr(settings, "CKEDITOR_5_FILE_STORAGE"):
return import_string(settings.CKEDITOR_5_FILE_STORAGE)
return import_string(settings.DEFAULT_FILE_STORAGE)
storage_setting = getattr(settings, "CKEDITOR_5_FILE_STORAGE", None)
default_storage_setting = getattr(settings, "DEFAULT_FILE_STORAGE", None)
storages_setting = getattr(settings, "STORAGES", {})
default_storage_name = storages_setting.get("default", {}).get("BACKEND")

if storage_setting:
return import_string(storage_setting)
elif default_storage_setting:
try:
return import_string(default_storage_setting)
except ImportError:
raise ImproperlyConfigured(f"Invalid default storage class: {default_storage_setting}")
elif default_storage_name:
try:
return import_string(default_storage_name)
except ImportError:
raise ImproperlyConfigured(f"Invalid default storage class: {default_storage_name}")
else:
raise ImproperlyConfigured(
"Either CKEDITOR_5_FILE_STORAGE, DEFAULT_FILE_STORAGE, or STORAGES['default'] setting is required.")


storage = get_storage_class()
Expand Down
Loading

0 comments on commit e6e2e96

Please sign in to comment.