Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enableReadOnlyMode & refactor upload_url to a class #195

Closed
wants to merge 15 commits into from

Conversation

juanbits
Copy link

@juanbits juanbits commented Mar 7, 2024

  • enableReadOnlyMode to disabled fields (close ckeditor is enabled on disabled textareas #192)
  • Refactor upload_file function to a class to can be overrided for the user
  • Enable image file rename using uuid via settings variable
  • Allow use custom upload_url via settings variable

@juanbits juanbits closed this Mar 8, 2024
@juanbits juanbits reopened this Mar 8, 2024
django_ckeditor_5/views.py Show resolved Hide resolved
README.rst Outdated Show resolved Hide resolved
README.rst Outdated Show resolved Hide resolved
@juanbits juanbits marked this pull request as draft March 13, 2024 00:14
@juanbits juanbits marked this pull request as ready for review March 13, 2024 00:23
Copy link
Contributor

@goapunk goapunk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, just a small comment about the renaming from file to image


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"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a potentially breaking change if anyone uses reverse("ck_editor_5_upload_file") (I do :) ). Is this renaming from file to image really necessary? If it is it should be marked as a breaking change somehow, there currently is no changelog but we probably should introduce one at some point. What do you think @hvlads ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@goapunk Well i decided to rename to image to be more semantic, considering the endpoint only allow upload images. Maybe is a good idea an this point create the changelog file and at least include the improvements in the next release, maybe the info:

  • rename url name
  • change view from function to class

Copy link
Contributor

@goapunk goapunk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the tests is failing for me now

@@ -19,7 +19,7 @@ def test_upload_file(admin_client, file):
def test_upload_file_to_google_cloud(admin_client, file, settings):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is oddly now failing for me but I think that's because it was not actually using storages.backends.gcloud.GoogleCloudStorage. I added some print statements and on master it uses articles.storage.CustomStorage, somehow override_settings was not working and now is. I'm not entirely sure why. Maybe we can remove this test as I personally don't want to make a request to the google cloud servers every time I run the tests. What do you think @hvlads ?

@@ -89,6 +89,9 @@ function createEditors(element = document.body) {
wordCountWrapper.innerHTML = '';
wordCountWrapper.appendChild(wordCountPlugin.wordCountContainer);
}
if(editorEl.hasAttribute("disabled")){
editor.enableReadOnlyMode( 'docs-snippet' );
Copy link
Owner

@hvlads hvlads Apr 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work on the code. Is it intended to use the same id for all editors?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hvlads sorry. I don't understand

Copy link
Owner

@hvlads hvlads Apr 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the lockId: string | symbol parameter:
This parameter serves as a unique identifier for setting the editor into a read-only state. It's essential to ensure that each lock Id is unique within your codebase.

editor.enableReadOnlyMode( 'my-feature-id' );
editor.enableReadOnlyMode( 'my-other-feature-id' );
// ...
editor.disableReadOnlyMode( 'my-feature-id' );
editor.isReadOnly; // true.
editor.disableReadOnlyMode( 'my-other-feature-id' );
editor.isReadOnly; // false.

Parameters
lockId : string | symbol
A unique ID for setting the editor to the read-only state.

In the loop, you're adding "docs-snippet" to all editors with the "disabled" attribute.

Shouldn't we do this?
const lockId = docs-snippet-${i};
editor.enableReadOnlyMode(lockId);

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Juanita, do you need any assistance with this? Also, I wanted to confirm if the class UploadImage View is still relevant now that files are being uploaded as well. Let me know if you need any clarification. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ckeditor is enabled on disabled textareas
3 participants