-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from eea/develop
fix: Create a content upgrade script to fix SVGs display [@dobri1408 - refs #276995]
- Loading branch information
Showing
5 changed files
with
62 additions
and
2 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
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,43 @@ | ||
"""Upgrade step for svgs to fix width and height""" | ||
|
||
import logging | ||
import transaction | ||
from plone.namedfile.utils import getImageInfo | ||
from zope.lifecycleevent import modified | ||
|
||
logger = logging.getLogger("upgrade_svgs") | ||
logger.setLevel(logging.INFO) | ||
|
||
|
||
def upgrade_svgs(portal): | ||
"""Upgrade SVG dimensions""" | ||
i = 0 | ||
for brain in portal.portal_catalog(): | ||
obj = brain.getObject() | ||
if ( | ||
hasattr(obj, "image") and hasattr(obj.image, "_width") and | ||
hasattr(obj.image, "_height") | ||
): | ||
logger.info("Processing %s", obj.absolute_url()) | ||
contentType, width, height = getImageInfo(obj.image.data) | ||
if contentType == "image/svg+xml": | ||
obj.image._width = width | ||
obj.image._height = height | ||
modified(obj.image) | ||
i += 1 | ||
if ( | ||
hasattr(obj, "preview_image") and | ||
hasattr(obj.preview_image, "_width") and | ||
hasattr(obj.preview_image, "_height") | ||
): | ||
logger.info("Processing %s", obj.absolute_url()) | ||
contentType, width, height = getImageInfo(obj.preview_image.data) | ||
if contentType == "image/svg+xml": | ||
obj.preview_image._width = width | ||
obj.preview_image._height = height | ||
modified(obj.preview_image) | ||
i += 1 | ||
if not i % 100: | ||
logger.info(i) | ||
transaction.commit() | ||
transaction.commit() |
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 |
---|---|---|
@@ -1 +1 @@ | ||
5.3 | ||
5.4 |