From fcd42025f3bbdba9ed554a6c497ccd5755d759e6 Mon Sep 17 00:00:00 2001 From: Vladislav Date: Sat, 6 Jan 2024 18:15:16 +0300 Subject: [PATCH] Update CKEditor 5 package, add type annotations, and improve error handling --- example/blog/articles/forms.py | 5 +++-- example/blog/articles/models.py | 4 +++- example/blog/blog/settings.py | 16 ++++++++-------- example/blog/manage.py | 5 +++-- example/blog/tests/test_upload_file.py | 6 ++++-- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/example/blog/articles/forms.py b/example/blog/articles/forms.py index 09a9c1b..c57932d 100644 --- a/example/blog/articles/forms.py +++ b/example/blog/articles/forms.py @@ -17,6 +17,7 @@ class Meta: fields = ("author", "text") widgets = { "text": CKEditor5Widget( - attrs={"class": "django_ckeditor_5"}, config_name="comment" - ) + attrs={"class": "django_ckeditor_5"}, + config_name="comment", + ), } diff --git a/example/blog/articles/models.py b/example/blog/articles/models.py index ace7370..3d8d124 100644 --- a/example/blog/articles/models.py +++ b/example/blog/articles/models.py @@ -24,7 +24,9 @@ class Comment(models.Model): author = models.CharField(max_length=250) text = CKEditor5Field("Text") article = models.ForeignKey( - Article, related_name="comments", on_delete=models.CASCADE + Article, + related_name="comments", + on_delete=models.CASCADE, ) class Meta: diff --git a/example/blog/blog/settings.py b/example/blog/blog/settings.py index e8614ee..bccec4f 100644 --- a/example/blog/blog/settings.py +++ b/example/blog/blog/settings.py @@ -79,7 +79,7 @@ "default": { "ENGINE": "django.db.backends.sqlite3", "NAME": os.path.join(BASE_DIR, "db.sqlite3"), - } + }, } # Password validation @@ -272,19 +272,19 @@ "title": "Heading 3", "class": "ck-heading_heading3", }, - ] + ], }, "list": { "properties": { "styles": True, "startIndex": True, "reversed": True, - } + }, }, "htmlSupport": { "allow": [ - {"name": "/.*/", "attributes": True, "classes": True, "styles": True} - ] + {"name": "/.*/", "attributes": True, "classes": True, "styles": True}, + ], }, "mention": { "feeds": [ @@ -299,14 +299,14 @@ "@Ted", ], "minimumCharacters": 1, - } - ] + }, + ], }, "style": { "definitions": [ {"name": "Article category", "element": "h3", "classes": ["category"]}, {"name": "Info box", "element": "p", "classes": ["info-box"]}, - ] + ], }, }, } diff --git a/example/blog/manage.py b/example/blog/manage.py index 83c4370..08d1064 100755 --- a/example/blog/manage.py +++ b/example/blog/manage.py @@ -9,11 +9,12 @@ def main(): try: from django.core.management import execute_from_command_line except ImportError as exc: - raise ImportError( + error_msg = ( "Couldn't import Django. Are you sure it's installed and " "available on your PYTHONPATH environment variable? Did you " "forget to activate a virtual environment?" - ) from exc + ) + raise ImportError(error_msg) from exc execute_from_command_line(sys.argv) diff --git a/example/blog/tests/test_upload_file.py b/example/blog/tests/test_upload_file.py index f734045..09899d1 100644 --- a/example/blog/tests/test_upload_file.py +++ b/example/blog/tests/test_upload_file.py @@ -5,7 +5,8 @@ def test_upload_file(admin_client, file): with file as upload: response = admin_client.post( - reverse("ck_editor_5_upload_file"), {"upload": upload} + reverse("ck_editor_5_upload_file"), + {"upload": upload}, ) assert response.status_code == 200 assert "url" in response.json() @@ -18,7 +19,8 @@ def test_upload_file(admin_client, file): def test_upload_file_to_google_cloud(admin_client, file, settings): with file as upload: response = admin_client.post( - reverse("ck_editor_5_upload_file"), {"upload": upload} + reverse("ck_editor_5_upload_file"), + {"upload": upload}, ) assert response.status_code == 200 assert "url" in response.json()