Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
ubuntu-20.04,
]
exclude:
- python-version: 3.7
requirements-file: dj32_cms41.txt
- python-version: 3.7
requirements-file: dj40_cms311.txt
- python-version: 3.7
Expand Down
26 changes: 11 additions & 15 deletions djangocms_text_ckeditor/picture_save.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
import os

from django.conf import settings
from django.core.files.base import ContentFile

from cms.models.pluginmodel import CMSPlugin


def create_picture_plugin(filename, file, parent_plugin, **kwargs):
try:
from djangocms_picture.models import Picture
except ImportError:
from cms.plugins.picture.models import Picture
from djangocms_picture.models import Picture

pic = Picture()
pic.placeholder = parent_plugin.placeholder
pic.parent = parent_plugin
pic.position = CMSPlugin.objects.filter(parent=parent_plugin).count()
pic.language = parent_plugin.language
pic.plugin_type = 'PicturePlugin'
path = pic.get_media_path(filename)
full_path = os.path.join(settings.MEDIA_ROOT, path)
if not os.path.exists(os.path.dirname(full_path)):
os.makedirs(os.path.dirname(full_path))
pic.image = path
f = open(full_path, 'wb')
f.write(file.read())
f.close()

# 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()
pic.picture = image_obj

pic.save()
return pic
36 changes: 36 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
HAS_DJANGOCMS_TRANSLATIONS = False


try:
import djangocms_picture # noqa
HAS_DJANGOCMS_PICTURE = True
except ImportError:
HAS_DJANGOCMS_PICTURE = False


class PluginActionsTestCase(TestFixture, BaseTestCase):

def get_custom_admin_url(self, plugin_class, name):
Expand Down Expand Up @@ -1079,3 +1086,32 @@ def test_textfield_with_untranslatable_children(self):

result = TextPlugin.set_translation_import_content(result, plugin)
self.assertDictEqual(result, {child1.pk: ''})


@unittest.skipUnless(
HAS_DJANGOCMS_PICTURE,
'Optional dependency djangocms-picture for tests is not installed.',
)
class DjangoCMSPictureIntegrationTestCase(TestFixture, BaseTestCase):
def setUp(self):
super().setUp()
self.page = self.create_page('test page', template='page.html', language='en')
self.placeholder = self.get_placeholders(self.page, 'en').get(slot='content')

def test_extract_images(self):
text_plugin = add_plugin(
self.placeholder,
'TextPlugin',
'en',
body='<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==">',
)

from djangocms_picture.models import Picture
picture_plugin = Picture.objects.order_by('-id')[0]
self.assertEqual(picture_plugin.parent.id, text_plugin.id)
self.assertHTMLEqual(
text_plugin.body,
'<cms-plugin alt="Image - unnamed file " title="Image - unnamed file" id="{}"></cms-plugin>'.format(
picture_plugin.id,
),
)