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
Gabriel Monnerat
erp5
Commits
62a887a6
Commit
62a887a6
authored
Jan 18, 2017
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Transforms: add getAvailableTargetMimetypeList method
parent
9052dff8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
0 deletions
+58
-0
product/PortalTransforms/TransformEngine.py
product/PortalTransforms/TransformEngine.py
+40
-0
product/PortalTransforms/utils.py
product/PortalTransforms/utils.py
+18
-0
No files found.
product/PortalTransforms/TransformEngine.py
View file @
62a887a6
...
...
@@ -30,6 +30,7 @@ from Products.PortalTransforms.transforms import initialize
from
Products.PortalTransforms.utils
import
log
from
Products.PortalTransforms.utils
import
TransformException
from
Products.PortalTransforms.utils
import
_www
from
Products.PortalTransforms.utils
import
parseContentType
from
ZODB.POSException
import
ConflictError
...
...
@@ -651,5 +652,44 @@ class TransformTool(UniqueObject, ActionProviderBase, Folder):
available_types
.
append
(
input
)
return
available_types
security
.
declarePublic
(
'getAvailableTargetMimetypeList'
)
def
getAvailableTargetMimetypeList
(
self
,
source_mimetype
):
"""
Returns a list of mimetypes that can be used as target for
`source_mimetype` conversion.
"""
# clean up mimetype from its useless characters
source_mimetype
=
parseContentType
(
source_mimetype
)
source_mimetype
=
";"
.
join
([
source_mimetype
.
gettype
()]
+
source_mimetype
.
getplist
())
# fill dict that will contain all possible conversion for each mimetype
input_output_dict
=
{}
# {"application/pdf": set(["text/html", "application/msword", ...])}
for
obj
in
self
.
objectValues
():
for
input_
in
obj
.
inputs
:
if
input_
in
input_output_dict
:
input_output_dict
[
input_
].
add
(
obj
.
output
)
else
:
input_output_dict
[
input_
]
=
set
([
obj
.
output
])
# browse mimetypes to fill result_set of available target mimetypes
result_set
=
set
([
source_mimetype
])
browsing_list
=
[
source_mimetype
]
input_output_items
=
input_output_dict
.
items
()
while
len
(
browsing_list
):
browsing_mimetype
=
browsing_list
.
pop
()
for
mimetype
,
output_mimetype_set
in
input_output_items
:
if
(
browsing_mimetype
==
mimetype
or
(
mimetype
.
endswith
(
"/*"
)
and
browsing_mimetype
[:
len
(
mimetype
[:
-
1
])]
==
mimetype
[:
-
1
])
):
for
output_mimetype
in
output_mimetype_set
:
if
output_mimetype
not
in
result_set
:
result_set
.
add
(
output_mimetype
)
browsing_list
.
append
(
output_mimetype
)
result_set
.
remove
(
source_mimetype
)
return
list
(
result_set
)
InitializeClass
(
TransformTool
)
registerToolInterface
(
'portal_transforms'
,
IPortalTransformsTool
)
product/PortalTransforms/utils.py
View file @
62a887a6
...
...
@@ -2,6 +2,9 @@
"""some common utilities
"""
import
mimetools
import
cStringIO
class
TransformException
(
Exception
):
pass
...
...
@@ -25,3 +28,18 @@ def safeToInt(value):
return
int
(
value
)
except
(
TypeError
,
ValueError
):
return
0
def
parseContentType
(
content_type
):
"""Parses `text/plain;charset="utf-8"` to a mimetools.Message object.
Note: Content type or MIME type are built like `maintype/subtype[;params]`.
parsed_content_type = parseContentType('text/plain;charset="utf-8"')
parsed_content_type.gettype() -> 'text/plain'
parsed_content_type.getmaintype() -> 'text'
parsed_content_type.getsubtype() -> 'plain'
parsed_content_type.getplist() -> 'charset="utf-8"'
parsed_content_type.getparam('charset') -> 'utf-8'
parsed_content_type.typeheader -> 'text/plain;charset="utf-8"'
"""
return
mimetools
.
Message
(
cStringIO
.
StringIO
(
"Content-Type:"
+
content_type
.
replace
(
"
\
r
\
n
"
,
"
\
r
\
n
\
t
"
)))
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