From f339c61f083ec0d2d152582528fdc8dfad4b7803 Mon Sep 17 00:00:00 2001 From: Juan Rendon Date: Wed, 6 Mar 2024 17:06:42 -0600 Subject: [PATCH 01/14] feat(app.js): enableReadOnlyMode on disabled fields --- django_ckeditor_5/static/django_ckeditor_5/app.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/django_ckeditor_5/static/django_ckeditor_5/app.js b/django_ckeditor_5/static/django_ckeditor_5/app.js index 9686c8c..2a73bc5 100644 --- a/django_ckeditor_5/static/django_ckeditor_5/app.js +++ b/django_ckeditor_5/static/django_ckeditor_5/app.js @@ -89,6 +89,9 @@ function createEditors(element = document.body) { wordCountWrapper.innerHTML = ''; wordCountWrapper.appendChild(wordCountPlugin.wordCountContainer); } + if(editorEl.hasAttribute("disabled")){ + editor.enableReadOnlyMode( 'docs-snippet' ); + } editors.push(editor); }).catch(error => { console.error((error)); From 5d15dae3ffe04cec33a738b55b8c3283e9f834f6 Mon Sep 17 00:00:00 2001 From: Juan Rendon Date: Wed, 6 Mar 2024 17:12:45 -0600 Subject: [PATCH 02/14] format(widgets.py): code format --- django_ckeditor_5/widgets.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/django_ckeditor_5/widgets.py b/django_ckeditor_5/widgets.py index 2145424..bfe4f37 100644 --- a/django_ckeditor_5/widgets.py +++ b/django_ckeditor_5/widgets.py @@ -38,7 +38,8 @@ def __init__(self, config_name="default", attrs=None): def format_error(self, ex): return "{} {}".format( - _("Check the correct settings.CKEDITOR_5_CONFIGS "), str(ex), + _("Check the correct settings.CKEDITOR_5_CONFIGS "), + str(ex), ) class Media: @@ -54,11 +55,11 @@ class Media: configs = getattr(settings, "CKEDITOR_5_CONFIGS", None) if configs is not None: for config in configs: - language = configs[config].get('language') + language = configs[config].get("language") if language: languages = [] - if isinstance(language, dict) and language.get('ui'): - language = language.get('ui') + if isinstance(language, dict) and language.get("ui"): + language = language.get("ui") elif isinstance(language, str): languages.append(language) elif isinstance(language, list): From 4643ba86c0f3523ac0b6d9be8226929846295418 Mon Sep 17 00:00:00 2001 From: Juan Rendon Date: Wed, 6 Mar 2024 17:17:36 -0600 Subject: [PATCH 03/14] feat(views.py): refactor upload_file def -> class to can be overrided & other improvements --- django_ckeditor_5/urls.py | 4 +- django_ckeditor_5/views.py | 107 +++++++++++++----------- example/blog/tests/test_upload_image.py | 26 ++++++ pyproject.toml | 2 +- 4 files changed, 86 insertions(+), 53 deletions(-) create mode 100644 example/blog/tests/test_upload_image.py diff --git a/django_ckeditor_5/urls.py b/django_ckeditor_5/urls.py index 3be48e4..e27749e 100644 --- a/django_ckeditor_5/urls.py +++ b/django_ckeditor_5/urls.py @@ -1,7 +1,7 @@ from django.urls import path -from . import views +from .views import UploadImageView urlpatterns = [ - path("image_upload/", views.upload_file, name="ck_editor_5_upload_file"), + path("image_upload/", UploadImageView.as_view(), name="ck_editor_5_upload_image"), ] diff --git a/django_ckeditor_5/views.py b/django_ckeditor_5/views.py index 4d76a0a..e74b088 100644 --- a/django_ckeditor_5/views.py +++ b/django_ckeditor_5/views.py @@ -7,9 +7,13 @@ else: from django.utils.translation import ugettext_lazy as _ +import os +import uuid + from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.http import JsonResponse +from django.views import View from PIL import Image from .forms import UploadFileForm @@ -19,56 +23,59 @@ class NoImageException(Exception): pass -def get_storage_class(): - 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: - error_msg = f"Invalid default storage class: {default_storage_setting}" +class UploadImageView(View): + def post(self, request, *args, **kwargs): + if request.user.is_staff or ( + not self.request.user.is_staff + and getattr(settings, "CKEDITOR_5_UPLOAD_IMAGES_ALLOW_ALL_USERS", None) + ): + form = UploadFileForm(request.POST, request.FILES) + try: + self.image_verify(request.FILES["upload"]) + except NoImageException as ex: + return JsonResponse({"error": {"message": f"{ex}"}}) + if form.is_valid(): + url = self.handle_uploaded_file(request.FILES["upload"]) + return JsonResponse({"url": url}) + raise Http404(_("Page not found.")) + + def get_storage_class(self): + 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: + error_msg = f"Invalid default storage class: {default_storage_setting}" + raise ImproperlyConfigured(error_msg) + elif default_storage_name: + try: + return import_string(default_storage_name) + except ImportError: + error_msg = f"Invalid default storage class: {default_storage_name}" + raise ImproperlyConfigured(error_msg) + else: + error_msg = ( + "Either CKEDITOR_5_FILE_STORAGE, DEFAULT_FILE_STORAGE, " + "or STORAGES['default'] setting is required." + ) raise ImproperlyConfigured(error_msg) - elif default_storage_name: - try: - return import_string(default_storage_name) - except ImportError: - error_msg = f"Invalid default storage class: {default_storage_name}" - raise ImproperlyConfigured(error_msg) - else: - error_msg = ("Either CKEDITOR_5_FILE_STORAGE, DEFAULT_FILE_STORAGE, " - "or STORAGES['default'] setting is required.") - raise ImproperlyConfigured(error_msg) - - -storage = get_storage_class() - - -def image_verify(f): - try: - Image.open(f).verify() - except OSError: - raise NoImageException - - -def handle_uploaded_file(f): - fs = storage() - filename = fs.save(f.name, f) - return fs.url(filename) - -def upload_file(request): - if request.method == "POST" and request.user.is_staff: - form = UploadFileForm(request.POST, request.FILES) + def image_verify(self, f): try: - image_verify(request.FILES["upload"]) - except NoImageException as ex: - return JsonResponse({"error": {"message": f"{ex}"}}) - if form.is_valid(): - url = handle_uploaded_file(request.FILES["upload"]) - return JsonResponse({"url": url}) - raise Http404(_("Page not found.")) + Image.open(f).verify() + except OSError: + raise NoImageException + + def handle_uploaded_file(self, f): + fs = self.get_storage_class()() + filename = f.name.lower() + if getattr(settings, "CKEDITOR_5_UPLOAD_IMAGES_RENAME_UUID", None) is True: + new_file_name = f"{uuid.uuid4()}{os.path.splitext(filename)[1]}" + filename = fs.save(new_file_name, f) + return fs.url(filename) diff --git a/example/blog/tests/test_upload_image.py b/example/blog/tests/test_upload_image.py new file mode 100644 index 0000000..e3797a5 --- /dev/null +++ b/example/blog/tests/test_upload_image.py @@ -0,0 +1,26 @@ +from django.test import override_settings +from django.urls import reverse + + +def test_upload_file(admin_client, file): + with file as upload: + response = admin_client.post( + reverse("ck_editor_5_upload_image"), + {"upload": upload}, + ) + assert response.status_code == 200 + assert "url" in response.json() + + +@override_settings( + CKEDITOR_5_FILE_STORAGE="storages.backends.gcloud.GoogleCloudStorage", + GS_BUCKET_NAME="test", +) +def test_upload_file_to_google_cloud(admin_client, file, settings): + with file as upload: + response = admin_client.post( + reverse("ck_editor_5_upload_image"), + {"upload": upload}, + ) + assert response.status_code == 200 + assert "url" in response.json() diff --git a/pyproject.toml b/pyproject.toml index c92b21f..fcf2f04 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -183,4 +183,4 @@ max-statements = 50 # Recommended: 50 "example/blog/manage.py" = ["TRY003"] "example/blog/blog/settings.py" = ["N816", "S105"] "example/blog/tests/*" = ["S101"] -"example/blog/tests/test_upload_file.py" = ["ARG001"] +"example/blog/tests/test_upload_image.py" = ["ARG001"] From 3ce6306ccad96db10cbbbdaa7a156eb9733e63d9 Mon Sep 17 00:00:00 2001 From: Juan Rendon Date: Wed, 6 Mar 2024 17:17:56 -0600 Subject: [PATCH 04/14] feat(widgets.py): allow use custom upload_url via settings variable --- django_ckeditor_5/widgets.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/django_ckeditor_5/widgets.py b/django_ckeditor_5/widgets.py index bfe4f37..75b2b51 100644 --- a/django_ckeditor_5/widgets.py +++ b/django_ckeditor_5/widgets.py @@ -81,7 +81,11 @@ def render(self, name, value, attrs=None, renderer=None): context["config"] = self.config context["script_id"] = "{}{}".format(attrs["id"], "_script") - context["upload_url"] = reverse("ck_editor_5_upload_file") + context["upload_url"] = reverse( + getattr( + settings, "CKEDITOR_5_UPLOAD_IMAGE_URL_NAME", "ck_editor_5_upload_image" + ) + ) context["csrf_cookie_name"] = settings.CSRF_COOKIE_NAME if self._config_errors: context["errors"] = ErrorList(self._config_errors) From 2ef957c7cc2f68e6a5a02ec427249e54e3bf795a Mon Sep 17 00:00:00 2001 From: Juan Rendon Date: Wed, 6 Mar 2024 17:37:47 -0600 Subject: [PATCH 05/14] fix(test_upload_file.py): delete file -> text_upload_image.py --- example/blog/tests/test_upload_file.py | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 example/blog/tests/test_upload_file.py diff --git a/example/blog/tests/test_upload_file.py b/example/blog/tests/test_upload_file.py deleted file mode 100644 index 09899d1..0000000 --- a/example/blog/tests/test_upload_file.py +++ /dev/null @@ -1,26 +0,0 @@ -from django.test import override_settings -from django.urls import reverse - - -def test_upload_file(admin_client, file): - with file as upload: - response = admin_client.post( - reverse("ck_editor_5_upload_file"), - {"upload": upload}, - ) - assert response.status_code == 200 - assert "url" in response.json() - - -@override_settings( - CKEDITOR_5_FILE_STORAGE="storages.backends.gcloud.GoogleCloudStorage", - GS_BUCKET_NAME="test", -) -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}, - ) - assert response.status_code == 200 - assert "url" in response.json() From 5e12536308cf8e970b9a2525d41a919950f4569b Mon Sep 17 00:00:00 2001 From: Juan Rendon Date: Wed, 6 Mar 2024 17:58:00 -0600 Subject: [PATCH 06/14] fix(README.rst): add info to use custom upload_url & rename images with uuid values --- README.rst | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/README.rst b/README.rst index 31bbce1..f9fe5c3 100644 --- a/README.rst +++ b/README.rst @@ -245,6 +245,52 @@ Custom storage example: base_url = urljoin(settings.MEDIA_URL, "django_ckeditor_5/") +Rename the uploaded images using uuid: +You can rename the images using uuid value and maintaning the extension in lower case. Example if your uploaded image original name was `my-image.JPG` now would be `acb34ded-f203-431a-9005-387cc24a892e.jpg` + +You need to specity the settings variable with True value +^^^^^^^^^^^^^^^^^^^^^^^ + .. code-block:: python + + CKEDITOR_5_UPLOAD_IMAGES_RENAME_UUID = True + + +Custom upload_url example: +You can use a custom upload_url to satisfy your needs. + +You need to create a custom view class that extends UploadImageView +^^^^^^^^^^^^^^^^^^^^^^^ + .. code-block:: python + + import os + import uuid + from django_ckeditor_5.views import UploadImageView + + + class CustomUploadImageView(UploadImageView): + """Custom View to upload images for django_ckeditor_5 images.""" + def handle_uploaded_file(self, f): + fs = self.get_storage_class()() + filename = f.name.lower() + # Here you can apply custom actions before the file is saved + if getattr(settings, "CKEDITOR_5_UPLOAD_IMAGES_RENAME_UUID", None) is True: + new_file_name = f"{uuid.uuid4()}{os.path.splitext(filename)[1]}" + filename = fs.save(new_file_name, f) + # Here you can apply custom actions after the file is saved + return fs.url(filename) + +You need to add the custom url to your app urls.py file +^^^^^^^^^^^^^^^^^^^^^^^ + .. code-block:: python + from . import views # or from .views import CkUploadImageView + path("custom_image_upload/", views.CkUploadImageView.as_view(),name="ck_editor_5_upload_image",), + +You need to specify in the settings the CKEDITOR_5_UPLOAD_IMAGE_URL_NAME variable with the name of your custom_image_upload url view +^^^^^^^^^^^^^^^^^^^^^^^ + .. code-block:: python + CKEDITOR_5_UPLOAD_IMAGE_URL_NAME = "your_app_name:ck_editor_5_upload_image" + + Changing the language: ^^^^^^^^^^^^^^^^^^^^^^ You can change the language via the ``language`` key in the config From 53be1af4e9f6aca3ab66e31289869958b70909c3 Mon Sep 17 00:00:00 2001 From: Juan Carlos Rendon Date: Wed, 6 Mar 2024 18:00:46 -0600 Subject: [PATCH 07/14] Update README.rst subtitles format --- README.rst | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index f9fe5c3..b70d653 100644 --- a/README.rst +++ b/README.rst @@ -246,20 +246,20 @@ Custom storage example: Rename the uploaded images using uuid: +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ You can rename the images using uuid value and maintaning the extension in lower case. Example if your uploaded image original name was `my-image.JPG` now would be `acb34ded-f203-431a-9005-387cc24a892e.jpg` You need to specity the settings variable with True value -^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: python CKEDITOR_5_UPLOAD_IMAGES_RENAME_UUID = True Custom upload_url example: +^^^^^^^^^^^^^^^^^^^^^^^ You can use a custom upload_url to satisfy your needs. You need to create a custom view class that extends UploadImageView -^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: python import os @@ -280,13 +280,11 @@ You need to create a custom view class that extends UploadImageView return fs.url(filename) You need to add the custom url to your app urls.py file -^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: python from . import views # or from .views import CkUploadImageView path("custom_image_upload/", views.CkUploadImageView.as_view(),name="ck_editor_5_upload_image",), You need to specify in the settings the CKEDITOR_5_UPLOAD_IMAGE_URL_NAME variable with the name of your custom_image_upload url view -^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: python CKEDITOR_5_UPLOAD_IMAGE_URL_NAME = "your_app_name:ck_editor_5_upload_image" From 33d464743cc51fb5bfe130ef55fd2fa92c2cd2c8 Mon Sep 17 00:00:00 2001 From: Juan Carlos Rendon Date: Wed, 6 Mar 2024 18:03:22 -0600 Subject: [PATCH 08/14] Update README.rst format --- README.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.rst b/README.rst index b70d653..b9ebece 100644 --- a/README.rst +++ b/README.rst @@ -250,6 +250,7 @@ Rename the uploaded images using uuid: You can rename the images using uuid value and maintaning the extension in lower case. Example if your uploaded image original name was `my-image.JPG` now would be `acb34ded-f203-431a-9005-387cc24a892e.jpg` You need to specity the settings variable with True value + .. code-block:: python CKEDITOR_5_UPLOAD_IMAGES_RENAME_UUID = True @@ -260,6 +261,7 @@ Custom upload_url example: You can use a custom upload_url to satisfy your needs. You need to create a custom view class that extends UploadImageView + .. code-block:: python import os @@ -280,11 +282,13 @@ You need to create a custom view class that extends UploadImageView return fs.url(filename) You need to add the custom url to your app urls.py file + .. code-block:: python from . import views # or from .views import CkUploadImageView path("custom_image_upload/", views.CkUploadImageView.as_view(),name="ck_editor_5_upload_image",), You need to specify in the settings the CKEDITOR_5_UPLOAD_IMAGE_URL_NAME variable with the name of your custom_image_upload url view + .. code-block:: python CKEDITOR_5_UPLOAD_IMAGE_URL_NAME = "your_app_name:ck_editor_5_upload_image" From 2843e58a1114823f9528412c2b314b1dc5a7554b Mon Sep 17 00:00:00 2001 From: Juan Carlos Rendon Date: Wed, 6 Mar 2024 18:05:59 -0600 Subject: [PATCH 09/14] Update README.rst format --- README.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.rst b/README.rst index b9ebece..cae77e2 100644 --- a/README.rst +++ b/README.rst @@ -284,12 +284,14 @@ You need to create a custom view class that extends UploadImageView You need to add the custom url to your app urls.py file .. code-block:: python + from . import views # or from .views import CkUploadImageView path("custom_image_upload/", views.CkUploadImageView.as_view(),name="ck_editor_5_upload_image",), You need to specify in the settings the CKEDITOR_5_UPLOAD_IMAGE_URL_NAME variable with the name of your custom_image_upload url view .. code-block:: python + CKEDITOR_5_UPLOAD_IMAGE_URL_NAME = "your_app_name:ck_editor_5_upload_image" From 994779761a585b6a6f3b6017f45c23a783835499 Mon Sep 17 00:00:00 2001 From: Juan Rendon Date: Thu, 7 Mar 2024 19:42:45 -0600 Subject: [PATCH 10/14] fix(views.py): save the image with original name or uuid name --- django_ckeditor_5/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/django_ckeditor_5/views.py b/django_ckeditor_5/views.py index e74b088..6db0e0d 100644 --- a/django_ckeditor_5/views.py +++ b/django_ckeditor_5/views.py @@ -76,6 +76,6 @@ def handle_uploaded_file(self, f): fs = self.get_storage_class()() filename = f.name.lower() if getattr(settings, "CKEDITOR_5_UPLOAD_IMAGES_RENAME_UUID", None) is True: - new_file_name = f"{uuid.uuid4()}{os.path.splitext(filename)[1]}" - filename = fs.save(new_file_name, f) - return fs.url(filename) + filename = f"{uuid.uuid4()}{os.path.splitext(filename)[1]}" + filesaved = fs.save(filename, f) + return fs.url(filesaved) From b1e14b84bd064e4ddab06f9e7b7d8617efb57f2c Mon Sep 17 00:00:00 2001 From: Juan Rendon Date: Fri, 8 Mar 2024 13:40:32 -0600 Subject: [PATCH 11/14] fix(views.py): improve check permissions for upload image --- django_ckeditor_5/views.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/django_ckeditor_5/views.py b/django_ckeditor_5/views.py index 6db0e0d..ae82c25 100644 --- a/django_ckeditor_5/views.py +++ b/django_ckeditor_5/views.py @@ -25,9 +25,10 @@ class NoImageException(Exception): class UploadImageView(View): def post(self, request, *args, **kwargs): - if request.user.is_staff or ( - not self.request.user.is_staff - and getattr(settings, "CKEDITOR_5_UPLOAD_IMAGES_ALLOW_ALL_USERS", None) + if ( + request.user.is_staff + or getattr(settings, "CKEDITOR_5_UPLOAD_IMAGES_ALLOW_ALL_USERS", None) + is True ): form = UploadFileForm(request.POST, request.FILES) try: From 8ed1d27359470e86e371df686a9f237619505321 Mon Sep 17 00:00:00 2001 From: Juan Rendon Date: Tue, 12 Mar 2024 18:08:15 -0600 Subject: [PATCH 12/14] fix(test_storage.py): update get_storage_class from the refactored View --- example/blog/tests/test_storage.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/example/blog/tests/test_storage.py b/example/blog/tests/test_storage.py index 264e14b..ab72d44 100644 --- a/example/blog/tests/test_storage.py +++ b/example/blog/tests/test_storage.py @@ -3,7 +3,7 @@ from django.test import override_settings from django.utils.module_loading import import_string -from django_ckeditor_5.views import get_storage_class +from django_ckeditor_5.views import UploadImageView @override_settings( @@ -13,20 +13,20 @@ ) def test_get_storage_class(settings): # Case 1: CKEDITOR_5_FILE_STORAGE is defined - storage_class = get_storage_class() + storage_class = UploadImageView().get_storage_class() assert storage_class == import_string(settings.CKEDITOR_5_FILE_STORAGE) # Case 2: DEFAULT_FILE_STORAGE is defined delattr(settings, "CKEDITOR_5_FILE_STORAGE") - storage_class = get_storage_class() + storage_class = UploadImageView().get_storage_class() assert storage_class == import_string(settings.DEFAULT_FILE_STORAGE) # Case 3: STORAGES['default'] is defined delattr(settings, "DEFAULT_FILE_STORAGE") - storage_class = get_storage_class() + storage_class = UploadImageView().get_storage_class() assert storage_class == import_string(settings.STORAGES["default"]["BACKEND"]) # Case 4: None of the required settings is defined delattr(settings, "STORAGES") with pytest.raises(ImproperlyConfigured): - get_storage_class() + UploadImageView().get_storage_class() From 8e79e4a6a198f453a438e99ca3bdc378c7ad9e6d Mon Sep 17 00:00:00 2001 From: Juan Rendon Date: Tue, 12 Mar 2024 18:11:25 -0600 Subject: [PATCH 13/14] fix(README.rst): change name of missing -> used classes --- README.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index cae77e2..e322d05 100644 --- a/README.rst +++ b/README.rst @@ -258,9 +258,9 @@ You need to specity the settings variable with True value Custom upload_url example: ^^^^^^^^^^^^^^^^^^^^^^^ -You can use a custom upload_url to satisfy your needs. +You can use a custom upload_url to satisfy your business logic needs. -You need to create a custom view class that extends UploadImageView +If you want to use a custom upload_url, You need to create a custom view class that extends UploadImageView .. code-block:: python @@ -285,10 +285,10 @@ You need to add the custom url to your app urls.py file .. code-block:: python - from . import views # or from .views import CkUploadImageView - path("custom_image_upload/", views.CkUploadImageView.as_view(),name="ck_editor_5_upload_image",), + from . import views # or from .views import CustomUploadImageView + path("custom_image_upload/", views.CustomUploadImageView.as_view(),name="ck_editor_5_upload_image",), -You need to specify in the settings the CKEDITOR_5_UPLOAD_IMAGE_URL_NAME variable with the name of your custom_image_upload url view +Finally You need to specify in the settings the CKEDITOR_5_UPLOAD_IMAGE_URL_NAME variable with the name of your custom_image_upload url view .. code-block:: python From 56c9791bffd453a144af99c66e368104dcd8c46f Mon Sep 17 00:00:00 2001 From: Juan Rendon Date: Tue, 12 Mar 2024 18:19:39 -0600 Subject: [PATCH 14/14] fix(README.rst): add example instructions --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index e322d05..5f1f4f2 100644 --- a/README.rst +++ b/README.rst @@ -274,7 +274,7 @@ If you want to use a custom upload_url, You need to create a custom view class t def handle_uploaded_file(self, f): fs = self.get_storage_class()() filename = f.name.lower() - # Here you can apply custom actions before the file is saved + # Here you can apply custom actions before the file is saved. For example optimize the image size if getattr(settings, "CKEDITOR_5_UPLOAD_IMAGES_RENAME_UUID", None) is True: new_file_name = f"{uuid.uuid4()}{os.path.splitext(filename)[1]}" filename = fs.save(new_file_name, f)