This repository was archived by the owner on Mar 26, 2025. It is now read-only.
-
Couldn't load subscription status.
- Fork 185
Support djangocms-picture 2.0.0 and higher in create_picture_plugin #660
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6ea4519
Support djangocms-picture 2.0.0 and higher in create_picture_plugin h…
leture ff9c2c5
Removed no longer used imports
leture 1023370
Added a test for helper extract_images which subsequently also tests …
leture fd837f8
Use assertHTMLEqual to be stable against different order of tag attri…
leture 3fa22ce
Exclude Django 3.2 / django-cms 4.1 under Python 3.7 from tests execu…
leture f201ce1
The current minium version for django-cms of 3.6 allows to remove the…
leture 5b02c31
Look in INSTALLED_APPS instead of import to check if djangocms_pictur…
leture File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -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 |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.