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
Xiaowu Zhang
erp5
Commits
f58c9938
Commit
f58c9938
authored
Nov 25, 2016
by
Tristan Cavelier
Committed by
Xiaowu Zhang
Aug 25, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
XXX onlyoffice hack on OOoDocument
parent
0c945082
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
5 deletions
+56
-5
bt5/erp5_base/DocumentTemplateItem/portal_components/document.erp5.OOoDocument.py
...mplateItem/portal_components/document.erp5.OOoDocument.py
+56
-5
No files found.
bt5/erp5_base/DocumentTemplateItem/portal_components/document.erp5.OOoDocument.py
View file @
f58c9938
...
...
@@ -151,6 +151,7 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi
def cached_getTargetFormatItemList(content_type):
from xmlrpclib import Fault
server_proxy = DocumentConversionServerProxy(self)
# XXX cloudooo3 needed to have allowed target list given by x2t + ooo
try:
allowed_target_item_list = server_proxy.getAllowedTargetItemList(
content_type)
...
...
@@ -179,7 +180,13 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi
DeprecationWarning)
# tuple order is reversed to be compatible with ERP5 Form
return [(y, x) for x, y in allowed]
return [(y, x) for x, y in allowed] + (
##### BEGIN hack - handle yformat (which should not be OOoDocument) XXX##
{"Text": [("OnlyOffice Text Document", "docy")],
"Spreadsheet": [("OnlyOffice Spreadsheet", "xlsy")],
"Presentation": [("OnlyOffice Presentation", "ppty")]}.get(self.getPortalType(), [])
##### END hack #####
)
# Cache valid format list
cached_getTargetFormatItemList = CachingMethod(
...
...
@@ -208,7 +215,24 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi
z.close()
return '
text
/
plain
', s
server_proxy = DocumentConversionServerProxy(self)
# XXX cloudooo3 needed to convert with x2t
orig_format = self.getBaseContentType()
##### BEGIN hack - handle yformat (should not be OOoDocument) XXX##
# XXX public cloudooo.erp5.net cannot handle x2t because of an OSError
__traceback_info__ = ("orig_format", orig_format, "format", format)
if format in ("docy", "application/x-asc-text+zip", "application/x-asc-text"):
encdata = server_proxy.convertFile(enc(str(self.getBaseData())), "odt", "docx")
#orig_format = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
return "application/x-asc-text", Pdata(dec(server_proxy.convertFile(encdata, "docx", "docy"))) # XXX change to application/x-asc-*+zip ?
if format in ("xsly", "application/x-asc-spreadsheet+zip", "application/x-asc-spreadsheet"):
encdata = server_proxy.convertFile(enc(str(self.getBaseData())), "ods", "xlsx")
#orig_format = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
return "application/x-asc-spreadsheet", Pdata(dec(server_proxy.convertFile(encdata, "xlsx", "xlsy"))) # XXX change to application/x-asc-*+zip ?
if format in ("ppty", "application/x-asc-presentation+zip", "application/x-asc-presentation"):
encdata = server_proxy.convertFile(enc(str(self.getBaseData())), "odp", "pptx")
#orig_format = "application/vnd.openxmlformats-officedocument.presentationml.presentation"
return "application/x-asc-presentation", Pdata(dec(server_proxy.convertFile(encdata, "pptx", "ppty"))) # XXX change to application/x-asc-*+zip ?
##### END hack #####
generate_result = server_proxy.run_generate(self.getId(),
enc(str(self.getBaseData())),
None,
...
...
@@ -291,12 +315,19 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi
self
.
setConversion
(
data
,
mime
,
format
=
original_format
)
return
mime
,
data
return
self
.
getConversion
(
format
=
original_format
)
try
:
__traceback_info__
=
repr
(
self
),
repr
(
self
.
getTargetFormatItemList
())
except
ConflictError
,
e
:
raise
e
except
Exception
,
e
:
__traceback_info__
=
str
(
e
)
# Raise an error if the format is not supported
if
not
self
.
isTargetFormatAllowed
(
format
):
raise
ConversionError
(
"OOoDocument: target format %s is not supported"
%
format
)
has_format
=
self
.
hasConversion
(
format
=
original_format
,
**
kw
)
if
not
has_format
:
# Do real conversion
# XXX think -> mime, data = self._getConversionFromPortalTransform(format)
mime
,
data
=
self
.
_getConversionFromProxyServer
(
format
)
if
is_html
:
# Extra processing required since
...
...
@@ -382,12 +413,31 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi
on the object. Update metadata information.
"""
server_proxy
=
DocumentConversionServerProxy
(
self
)
# XXX cloudooo3 needed to have x2t convert available
##### BEGIN hack - handle yformat (which should not be OOoDocument) XXX##
content_type
=
self
.
getContentType
()
filename
=
self
.
getFilename
()
or
self
.
getId
()
if
content_type
in
(
"application/x-asc-text+zip"
,
"application/x-asc-text"
):
encdata
=
server_proxy
.
convertFile
(
enc
(
str
(
self
.
getData
())),
"docy"
,
"docx"
)
content_type
=
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
filename
+=
".docx"
elif
content_type
in
(
"application/x-asc-spreadsheet+zip"
,
"application/x-asc-spreadsheet"
):
encdata
=
server_proxy
.
convertFile
(
enc
(
str
(
self
.
getData
())),
"xlsy"
,
"xlsx"
)
content_type
=
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
filename
+=
".xlsx"
elif
content_type
in
(
"application/x-asc-presentation+zip"
,
"application/x-asc-presentation"
):
encdata
=
server_proxy
.
convertFile
(
enc
(
str
(
self
.
getData
())),
"ppty"
,
"pptx"
)
content_type
=
"application/vnd.openxmlformats-officedocument.presentationml.presentation"
filename
+=
".pptx"
else
:
encdata
=
enc
(
str
(
self
.
getData
()))
##### END hack #####
response_code
,
response_dict
,
response_message
=
server_proxy
.
run_convert
(
self
.
getFilename
()
or
self
.
getId
()
,
enc
(
str
(
self
.
getData
()))
,
filename
,
enc
data
,
None
,
None
,
self
.
getContentType
()
)
content_type
)
if
response_code
==
200
:
# sucessfully converted document
self
.
_setBaseData
(
dec
(
response_dict
[
'data'
]))
...
...
@@ -421,6 +471,7 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi
raise
NotConvertedError
()
server_proxy
=
DocumentConversionServerProxy
(
self
)
# XXX cloudooo3 needed to have setMetadata on x2t
response_code
,
response_dict
,
response_message
=
\
server_proxy
.
run_setmetadata
(
self
.
getId
(),
enc
(
str
(
self
.
getBaseData
())),
...
...
@@ -432,4 +483,4 @@ class OOoDocument(OOoDocumentExtensibleTraversableMixin, BaseConvertableFileMixi
else
:
# Explicitly raise the exception!
raise
ConversionError
(
"OOoDocument: error getting document metadata (Code %s: %s)"
%
(
response_code
,
response_message
))
%
(
response_code
,
response_message
))
\ No newline at end of file
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