appy.pod: added .docx and .xlsx as conversion formats for converter.py. appy.gen: translation system: if not message is present, the label itself is used for the message.
This commit is contained in:
parent
e5cef2b8a4
commit
41fbedd279
|
@ -1088,9 +1088,13 @@ class BaseMixin:
|
||||||
# Fallback to 'en'.
|
# Fallback to 'en'.
|
||||||
translation = getattr(tool, 'en').appy()
|
translation = getattr(tool, 'en').appy()
|
||||||
res = getattr(translation, label, '')
|
res = getattr(translation, label, '')
|
||||||
# Perform replacements if needed
|
# If still no result, put the label instead of a translated message
|
||||||
for name, repl in mapping.iteritems():
|
if not res: res = label
|
||||||
res = res.replace('${%s}' % name, repl)
|
else:
|
||||||
|
# Perform replacements
|
||||||
|
res = res.replace('\r\n', '<br/>').replace('\n', '<br/>')
|
||||||
|
for name, repl in mapping.iteritems():
|
||||||
|
res = res.replace('${%s}' % name, repl)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def getPageLayout(self, layoutType):
|
def getPageLayout(self, layoutType):
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
import os.path
|
||||||
|
import appy
|
||||||
|
from appy.shared.utils import executeCommand
|
||||||
from appy.gen.plone25.wrappers import AbstractWrapper
|
from appy.gen.plone25.wrappers import AbstractWrapper
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -109,4 +112,14 @@ class ToolWrapper(AbstractWrapper):
|
||||||
def getAvailableLanguages(self):
|
def getAvailableLanguages(self):
|
||||||
'''Returns the list of available languages for this application.'''
|
'''Returns the list of available languages for this application.'''
|
||||||
return [(t.id, t.title) for t in self.translations]
|
return [(t.id, t.title) for t in self.translations]
|
||||||
|
|
||||||
|
def convert(self, fileName, format):
|
||||||
|
'''Launches a UNO-enabled Python interpreter as defined in the self for
|
||||||
|
converting, using OpenOffice in server mode, a file named p_fileName
|
||||||
|
into an output p_format.'''
|
||||||
|
convScript = '%s/pod/converter.py' % os.path.dirname(appy.__file__)
|
||||||
|
cmd = '%s %s "%s" %s -p%d' % (self.unoEnabledPython, convScript,
|
||||||
|
fileName, format, self.openOfficePort)
|
||||||
|
self.log('Executing %s...' % cmd)
|
||||||
|
return executeCommand(cmd) # The result can contain an error message
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
|
@ -291,10 +291,7 @@ class FileWrapper:
|
||||||
if format:
|
if format:
|
||||||
if not tool: return
|
if not tool: return
|
||||||
# Convert the dumped file using OpenOffice
|
# Convert the dumped file using OpenOffice
|
||||||
convScript = '%s/converter.py' % os.path.dirname(appy.pod.__file__)
|
errorMessage = tool.convert(filePath, format)
|
||||||
cmd = '%s %s "%s" %s -p%d' % (tool.unoEnabledPython, convScript,
|
|
||||||
filePath, format, tool.openOfficePort)
|
|
||||||
errorMessage = executeCommand(cmd)
|
|
||||||
# Even if we have an "error" message, it could be a simple warning.
|
# Even if we have an "error" message, it could be a simple warning.
|
||||||
# So we will continue here and, as a subsequent check for knowing if
|
# So we will continue here and, as a subsequent check for knowing if
|
||||||
# an error occurred or not, we will test the existence of the
|
# an error occurred or not, we will test the existence of the
|
||||||
|
|
|
@ -37,6 +37,8 @@ FILE_TYPES = {'odt': 'writer8',
|
||||||
'doc': 'MS Word 97',
|
'doc': 'MS Word 97',
|
||||||
'xls': 'MS Excel 97',
|
'xls': 'MS Excel 97',
|
||||||
'ppt': 'MS PowerPoint 97',
|
'ppt': 'MS PowerPoint 97',
|
||||||
|
'docx': 'MS Word 2007 XML',
|
||||||
|
'xlsx': 'Calc MS Excel 2007 XML',
|
||||||
}
|
}
|
||||||
# Conversion from odt to odt does not make any conversion, but updates indexes
|
# Conversion from odt to odt does not make any conversion, but updates indexes
|
||||||
# and linked documents.
|
# and linked documents.
|
||||||
|
@ -57,7 +59,7 @@ DEFAULT_PORT = 2002
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
class Converter:
|
class Converter:
|
||||||
'''Converts an document readable by OpenOffice into pdf, doc, txt or rtf.'''
|
'''Converts a document readable by OpenOffice into pdf, doc, txt, rtf...'''
|
||||||
exeVariants = ('soffice.exe', 'soffice')
|
exeVariants = ('soffice.exe', 'soffice')
|
||||||
pathReplacements = {'program files': 'progra~1',
|
pathReplacements = {'program files': 'progra~1',
|
||||||
'openoffice.org 1': 'openof~1',
|
'openoffice.org 1': 'openof~1',
|
||||||
|
@ -194,11 +196,19 @@ class Converter:
|
||||||
from com.sun.star.beans import PropertyValue
|
from com.sun.star.beans import PropertyValue
|
||||||
try:
|
try:
|
||||||
# Loads the document to convert in a new hidden frame
|
# Loads the document to convert in a new hidden frame
|
||||||
prop = PropertyValue()
|
prop = PropertyValue(); prop.Name = 'Hidden'; prop.Value = True
|
||||||
prop.Name = 'Hidden'
|
if self.inputType == 'csv':
|
||||||
prop.Value = True
|
prop2 = PropertyValue()
|
||||||
|
prop2.Name = 'FilterFlags'
|
||||||
|
prop2.Value = '59,34,76,1'
|
||||||
|
#prop2.Name = 'FilterData'
|
||||||
|
#prop2.Value = 'Any'
|
||||||
|
props = (prop, prop2)
|
||||||
|
else:
|
||||||
|
props = (prop,)
|
||||||
|
# Give some additional params if we need to open a CSV file
|
||||||
self.doc = self.oo.loadComponentFromURL(self.docUrl, "_blank", 0,
|
self.doc = self.oo.loadComponentFromURL(self.docUrl, "_blank", 0,
|
||||||
(prop,))
|
props)
|
||||||
if self.inputType == 'odt':
|
if self.inputType == 'odt':
|
||||||
# Perform additional tasks for odt documents
|
# Perform additional tasks for odt documents
|
||||||
self.updateOdtDocument()
|
self.updateOdtDocument()
|
||||||
|
|
Loading…
Reference in a new issue