Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Georgios Dagkakis
erp5
Commits
6731ccd8
Commit
6731ccd8
authored
Jan 20, 2012
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Include only local images.
Fix url calculation. Pass only applicable arguments to conversion API.
parent
d9f83777
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
8 deletions
+21
-8
product/ERP5OOo/tests/testDms.py
product/ERP5OOo/tests/testDms.py
+11
-7
product/ERP5OOo/transforms/oood_commandtransform.py
product/ERP5OOo/transforms/oood_commandtransform.py
+10
-1
No files found.
product/ERP5OOo/tests/testDms.py
View file @
6731ccd8
...
...
@@ -2021,7 +2021,8 @@ return 1
def
test_convertWebPageWithEmbeddedZODBImageToImageOnTraversal
(
self
):
"""
Test Web Page using embedded Images into ZODB case (in its HTML body)
Test Web Page conversion to image using embedded Images into its HTML body.
Test various dumb ways to include an image (relative to instance or external ones).
"""
display
=
'thumbnail'
convert_kw
=
{
'display'
:
display
,
...
...
@@ -2037,36 +2038,39 @@ return 1
web_page_image_size
,
web_page_file_size
=
self
.
getURLSizeList
(
web_page_document_url
,
**
convert_kw
)
self
.
assertTrue
(
max
(
preffered_size_for_display
)
-
max
(
web_page_image_size
)
<=
1
)
# XXX: how to simulate the case when web page contains (through reference) link to document for which based conversion failed?
# XXX: how to fix case when web page contains (through reference) link to itself (causes infinite recursion)
# images from same instance accessed by reference and wrong arguments (dispay NOT display)
# images from same instance accessed by reference and wrong conversion arguments (dispay NOT display)
# code should be more resilient
upload_file
=
makeFileUpload
(
'cmyk_sample.jpg'
)
image
=
self
.
portal
.
image_module
.
newContent
(
portal_type
=
'Image'
,
reference
=
'Embedded-XXX'
,
version
=
'001'
,
language
=
'en'
)
image
.
setData
(
upload_file
.
read
())
image
.
publish
()
convert_kw
[
'quality'
]
=
99
# to not get cached
web_page_document
=
self
.
portal
.
web_page_module
.
newContent
(
portal_type
=
"Web Page"
)
web_page_document
.
setTextContent
(
'''<b> test </b><img src="Embedded-XXX?format=jpeg&dispay=medium"/>'''
)
web_page_document
.
setTextContent
(
'''<b> test </b><img src="Embedded-XXX?format=jpeg&dispay=medium
&quality=50
"/>'''
)
self
.
stepTic
()
web_page_document_url
=
'%s/%s'
%
(
self
.
portal
.
absolute_url
(),
web_page_document
.
getRelativeUrl
())
web_page_image_size
,
web_page_file_size
=
self
.
getURLSizeList
(
web_page_document_url
,
**
convert_kw
)
self
.
assertTrue
(
max
(
preffered_size_for_display
)
-
max
(
web_page_image_size
)
<=
1
)
# external images
convert_kw
[
'quality'
]
=
98
# to not get cached
convert_kw
[
'quality'
]
=
98
web_page_document
=
self
.
portal
.
web_page_module
.
newContent
(
portal_type
=
"Web Page"
)
web_page_document
.
setTextContent
(
'''<b> test </b><img src="http://www.erp5.com/images/favourite.png"/>
<img style="width: 26px; height: 26px;" src="http://www.erp5.com//images/save2.png" />
<img style="width: 26px; height: 26px;" src="http:////www.erp5.com//images/save2.png" />
<img style="width: 26px; height: 26px;" src="http://www.erp5.com/./images/save2.png" />
'''
)
self
.
stepTic
()
web_page_document_url
=
'%s/%s'
%
(
self
.
portal
.
absolute_url
(),
web_page_document
.
getRelativeUrl
())
web_page_image_size
,
web_page_file_size
=
self
.
getURLSizeList
(
web_page_document_url
,
**
convert_kw
)
self
.
assertTrue
(
max
(
preffered_size_for_display
)
-
max
(
web_page_image_size
)
<=
1
)
# XXX: how to simulate the case when web page contains (through reference) link to document for which based conversion failed?
# XXX: how to fix case when web page contains (through reference) link to itself (causes infinite recursion)
def
test_convertToImageOnTraversal
(
self
):
"""
...
...
product/ERP5OOo/transforms/oood_commandtransform.py
View file @
6731ccd8
...
...
@@ -110,8 +110,10 @@ class OOOdCommandTransform(commandtransform):
url
=
href_attribute_list
[
0
]
parse_result
=
urlparse
(
unquote
(
url
))
# urlparse return a 6-tuple: scheme, netloc, path, params, query, fragment
netloc
=
parse_result
[
1
]
path
=
parse_result
[
2
]
if
path
:
if
path
and
netloc
in
(
''
,
None
):
# it makes sense to include only relative to current site images not remote ones which can be taken by OOo
# OOo corrupt relative Links inside HTML content during odt conversion
# <img src="REF.TO.IMAGE" ... /> become <draw:image xlink:href="../REF.TO.IMAGE" ... />
# So remove "../" added by OOo
...
...
@@ -119,6 +121,9 @@ class OOOdCommandTransform(commandtransform):
# in some cases like Web Page content "/../" can be contained in image URL which will break
# restrictedTraverse calls, our best guess is to remove it
path
=
path
.
replace
(
'/../'
,
''
)
# remove occurencies of '//' or '///' in path (happens with web pages) and leave
# a traversable relative URL
path
=
'/'
.
join
([
x
for
x
in
path
.
split
(
'/'
)
if
x
.
strip
()
!=
''
])
# retrieve http parameters and use them to convert image
query_parameter_string
=
parse_result
[
4
]
image_parameter_dict
=
dict
(
parse_qsl
(
query_parameter_string
))
...
...
@@ -131,6 +136,10 @@ class OOOdCommandTransform(commandtransform):
odt_content_modified
=
True
content_type
=
image
.
getContentType
()
format
=
image_parameter_dict
.
pop
(
'format'
,
None
)
# convert API accepts only a certail range of arguments
for
key
,
value
in
image_parameter_dict
.
items
():
if
key
not
in
(
'format'
,
'display'
,
'quality'
,
'resolution'
,):
image_parameter_dict
.
pop
(
key
)
if
getattr
(
image
,
'convert'
,
None
)
is
not
None
:
# The document support conversion so perform conversion
# according given parameters
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment