Commit 025b2311 authored by Nicolas Delaby's avatar Nicolas Delaby

handle KeyError Exception when it try to get a Document from ZODB

Handle case when css_object is not a DTMLDocument


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@23234 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ed918105
...@@ -2,6 +2,7 @@ from Products.PortalTransforms.libtransforms.commandtransform import commandtran ...@@ -2,6 +2,7 @@ from Products.PortalTransforms.libtransforms.commandtransform import commandtran
from Products.PortalTransforms.interfaces import idatastream from Products.PortalTransforms.interfaces import idatastream
from Products.ERP5Type.Document import newTempOOoDocument from Products.ERP5Type.Document import newTempOOoDocument
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from Acquisition import aq_base
try: try:
from Products.ERP5OOo.OOoUtils import OOoBuilder from Products.ERP5OOo.OOoUtils import OOoBuilder
import re import re
...@@ -86,7 +87,7 @@ class OOOdCommandTransform(commandtransform): ...@@ -86,7 +87,7 @@ class OOOdCommandTransform(commandtransform):
path = matching.groupdict().get('path') path = matching.groupdict().get('path')
try: try:
image = self.context.restrictedTraverse(path) image = self.context.restrictedTraverse(path)
except AttributeError: except (AttributeError, KeyError):
#Image not found, this image is probably not hosted by ZODB. Do nothing #Image not found, this image is probably not hosted by ZODB. Do nothing
image = None image = None
if image is not None: if image is not None:
...@@ -102,7 +103,7 @@ class OOOdCommandTransform(commandtransform): ...@@ -102,7 +103,7 @@ class OOOdCommandTransform(commandtransform):
data = image.getData() data = image.getData()
height = image.getHeight() height = image.getHeight()
width = image.getWidth() width = image.getWidth()
except AttributeError: except (AttributeError, KeyError):
#OFS API #OFS API
data = image.data data = image.data
height = image.height height = image.height
...@@ -137,12 +138,17 @@ class OOOdCommandTransform(commandtransform): ...@@ -137,12 +138,17 @@ class OOOdCommandTransform(commandtransform):
if matching is not None: if matching is not None:
path = matching.groupdict().get('path') path = matching.groupdict().get('path')
try: try:
css = self.context.restrictedTraverse(path) css_object = self.context.restrictedTraverse(path)
except AttributeError: except (AttributeError, KeyError):
#Image not found, this image is probably not hosted by ZODB. Do nothing #Image not found, this image is probably not hosted by ZODB. Do nothing
css = None css_object = None
if css is not None: if css_object is not None:
css_as_text = css(client=self.context.getPortalObject()) if callable(aq_base(css_object)):
#In case of DTMLDocument
css_as_text = css_object(client=self.context.getPortalObject())
else:
#Other cases like files
css_as_text = str(css_object)
style_node = xml_doc.newChild(None, 'style', css_as_text) style_node = xml_doc.newChild(None, 'style', css_as_text)
style_node.setProp('type', 'text/css') style_node.setProp('type', 'text/css')
css_link_tag.replaceNode(style_node) css_link_tag.replaceNode(style_node)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment