-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add drag and drop support for djangocms-text-ckeditor (#165)
Co-authored-by: Steffen Jasper <[email protected]>
- Loading branch information
Showing
8 changed files
with
106 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,4 @@ | |
13. Github actions will publish the new package to pypi | ||
""" | ||
|
||
__version__ = "1.1.10" | ||
__version__ = "1.2.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from django.core.files.base import ContentFile | ||
|
||
from djangocms_frontend.contrib.image.cms_plugins import ImagePlugin | ||
from djangocms_frontend.contrib.image.forms import get_templates | ||
from djangocms_frontend.contrib.image.models import Image | ||
from djangocms_frontend.helpers import add_plugin, first_choice | ||
|
||
default_template = first_choice(get_templates()) | ||
|
||
|
||
def create_image_plugin(filename, file, parent_plugin, **kwargs): | ||
|
||
# Set the FilerImageField value. | ||
from filer.settings import FILER_IMAGE_MODEL | ||
from filer.utils.loader import load_model | ||
image_class = load_model(FILER_IMAGE_MODEL) | ||
image_obj = image_class(file=ContentFile(file.read(), name=filename)) | ||
image_obj.save() | ||
|
||
img = Image( | ||
parent=parent_plugin, | ||
position=parent_plugin.position + 1, | ||
placeholder=parent_plugin.placeholder, | ||
language=parent_plugin.language, | ||
plugin_type=ImagePlugin.__name__, | ||
ui_item=Image.__class__.__name__, | ||
config={}, | ||
).initialize_from_form() | ||
img.config.update({ | ||
"picture": {"pk": image_obj.pk, "model": "filer.image"}, | ||
"use_no_cropping": True, | ||
}) | ||
add_plugin(parent_plugin.placeholder, img) | ||
|
||
return img |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from cms.api import add_plugin | ||
from cms.test_utils.testcases import CMSTestCase | ||
|
||
from djangocms_frontend.contrib.image.models import Image | ||
from tests.fixtures import TestFixture | ||
|
||
|
||
class DjangoCMSPictureIntegrationTestCase(TestFixture, CMSTestCase): | ||
def setUp(self): | ||
super().setUp() | ||
self.placeholder = self.get_placeholders(self.home).get(slot='content') | ||
|
||
def test_extract_images(self): | ||
text_plugin = add_plugin( | ||
self.placeholder, | ||
'TextPlugin', | ||
'en', | ||
body='<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42m' | ||
'P8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==">', | ||
) | ||
|
||
picture_plugins = Image.objects.order_by('-id') | ||
self.assertEqual(len(picture_plugins), 1) | ||
self.assertEqual(picture_plugins[0].parent.id, text_plugin.id) | ||
id = picture_plugins[0].id | ||
self.assertHTMLEqual( | ||
text_plugin.body, | ||
f'<cms-plugin alt="Picture / Image - Image ({id}) " ' | ||
f'title="Picture / Image - Image ({id})" ' | ||
f'id="{id}"></cms-plugin>', | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters