Bugfix when contacting OO; various bugfixes and improvements.

This commit is contained in:
Gaetan Delannay 2009-11-20 20:17:06 +01:00
parent cf3748bf77
commit 7435ff1601
5 changed files with 33 additions and 23 deletions

View file

@ -17,6 +17,9 @@ from descriptors import ArchetypeFieldDescriptor, ArchetypesClassDescriptor, \
COMMON_METHODS = ''' COMMON_METHODS = '''
def getTool(self): return self.%s def getTool(self): return self.%s
def getProductConfig(self): return Products.%s.config def getProductConfig(self): return Products.%s.config
def skynView(self):
"""Redirects to skyn/view."""
return self.REQUEST.RESPONSE.redirect(self.getUrl())
''' '''
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
class Generator(AbstractGenerator): class Generator(AbstractGenerator):

View file

@ -37,7 +37,7 @@ class PloneInstaller:
self.ploneStuff = ploneStuff # A dict of some Plone functions or vars self.ploneStuff = ploneStuff # A dict of some Plone functions or vars
self.toLog = StringIO() self.toLog = StringIO()
self.typeAliases = {'sharing': '', 'gethtml': '', self.typeAliases = {'sharing': '', 'gethtml': '',
'(Default)': 'skyn/view', 'edit': 'skyn/edit', '(Default)': 'skynView', 'edit': 'skyn/edit',
'index.html': '', 'properties': '', 'view': ''} 'index.html': '', 'properties': '', 'view': ''}
self.tool = None # The Plone version of the application tool self.tool = None # The Plone version of the application tool
self.appyTool = None # The Appy version of the application tool self.appyTool = None # The Appy version of the application tool
@ -162,7 +162,7 @@ class PloneInstaller:
typeActions = typeInfo.listActions() typeActions = typeInfo.listActions()
for action in typeActions: for action in typeActions:
if action.id == 'view': if action.id == 'view':
page = 'skyn/view' page = 'skynView'
action.edit(action='string:${object_url}/%s' % page) action.edit(action='string:${object_url}/%s' % page)
elif action.id == 'edit': elif action.id == 'edit':
page = 'skyn/edit' page = 'skyn/edit'

View file

@ -328,7 +328,9 @@
<tr tal:define="odd repeat/items/odd; <tr tal:define="odd repeat/items/odd;
rhComments items/comments|nothing; rhComments items/comments|nothing;
state items/review_state|nothing" state items/review_state|nothing"
tal:attributes="class python:test(odd, 'even', 'odd')" tal:condition="items/action"> tal:condition="python: items['action'] and (rhComments != '_invisible_')"
tal:attributes="class python:test(odd, 'even', 'odd')">
<td tal:content="python: tool.translate(contextObj.getWorkflowLabel(items['action']))" <td tal:content="python: tool.translate(contextObj.getWorkflowLabel(items['action']))"
tal:attributes="class string:state-${state}"/> tal:attributes="class string:state-${state}"/>
<td tal:define="actorid python:items.get('actor'); <td tal:define="actorid python:items.get('actor');

View file

@ -185,12 +185,9 @@ class AbstractWrapper:
self.link(fieldName, ploneObj) self.link(fieldName, ploneObj)
self.o.reindexObject() self.o.reindexObject()
# Call custom initialization # Call custom initialization
try: if externalData: param = externalData
if externalData: param = externalData else: param = True
else: param = True if hasattr(appyObj, 'onEdit'): appyObj.onEdit(param)
appyObj.onEdit(param)
except AttributeError:
pass
ploneObj.reindexObject() ploneObj.reindexObject()
return appyObj return appyObj
@ -198,13 +195,16 @@ class AbstractWrapper:
'''Check documentation of self.o.translate.''' '''Check documentation of self.o.translate.'''
return self.o.translate(label, mapping, domain) return self.o.translate(label, mapping, domain)
def do(self, transition, comment='', doAction=False, doNotify=False): def do(self, transition, comment='', doAction=False, doNotify=False,
doHistory=True):
'''This method allows to trigger on p_self a workflow p_transition '''This method allows to trigger on p_self a workflow p_transition
programmatically. If p_doAction is False, the action that must programmatically. If p_doAction is False, the action that must
normally be executed after the transition has been triggered will normally be executed after the transition has been triggered will
not be executed. If p_doNotify is False, the notifications not be executed. If p_doNotify is False, the notifications
(email,...) that must normally be launched after the transition has (email,...) that must normally be launched after the transition has
been triggered will not be launched.''' been triggered will not be launched. If p_doHistory is False, there
will be no trace from this transition triggering in the workflow
history.'''
wfTool = self.o.portal_workflow wfTool = self.o.portal_workflow
availableTransitions = [t['id'] for t in \ availableTransitions = [t['id'] for t in \
wfTool.getTransitionsFor(self.o)] wfTool.getTransitionsFor(self.o)]
@ -222,6 +222,12 @@ class AbstractWrapper:
# (actions, notifications) after the transition has been executed by DC # (actions, notifications) after the transition has been executed by DC
# workflow. # workflow.
self.o._v_appy_do = {'doAction': doAction, 'doNotify': doNotify} self.o._v_appy_do = {'doAction': doAction, 'doNotify': doNotify}
if not doHistory:
comment = '_invisible_' # Will not be displayed.
# At first sight, I wanted to remove the entry from
# self.o.workflow_history. But Plone determines the state of an
# object by consulting the target state of the last transition in
# this workflow_history.
wfTool.doActionFor(self.o, transitionName, comment=comment) wfTool.doActionFor(self.o, transitionName, comment=comment)
del self.o._v_appy_do del self.o._v_appy_do

View file

@ -17,7 +17,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
import sys, os, os.path, time, signal, unicodedata import sys, os, os.path, time, signal
from optparse import OptionParser from optparse import OptionParser
ODT_FILE_TYPES = {'doc': 'MS Word 97', # Could be 'MS Word 2003 XML' ODT_FILE_TYPES = {'doc': 'MS Word 97', # Could be 'MS Word 2003 XML'
@ -54,20 +54,19 @@ class Converter:
} }
def __init__(self, docPath, resultType, port=DEFAULT_PORT): def __init__(self, docPath, resultType, port=DEFAULT_PORT):
self.port = port self.port = port
self.docUrl = self.getDocUrl(docPath) self.docUrl, self.docPath = self.getDocUrls(docPath)
self.docUrlStr = unicodedata.normalize('NFKD', self.docUrl).encode(
"ascii", "ignore")
self.resultFilter = self.getResultFilter(resultType) self.resultFilter = self.getResultFilter(resultType)
self.resultUrl = self.getResultUrl(resultType) self.resultUrl = self.getResultUrl(resultType)
self.ooContext = None self.ooContext = None
self.oo = None # OpenOffice application object self.oo = None # OpenOffice application object
self.doc = None # OpenOffice loaded document self.doc = None # OpenOffice loaded document
def getDocUrl(self, docPath): def getDocUrls(self, docPath):
import uno import uno
if not os.path.exists(docPath) and not os.path.isfile(docPath): if not os.path.exists(docPath) and not os.path.isfile(docPath):
raise ConverterError(DOC_NOT_FOUND % docPath) raise ConverterError(DOC_NOT_FOUND % docPath)
docAbsPath = os.path.abspath(docPath) docAbsPath = os.path.abspath(docPath)
return uno.systemPathToFileUrl(docAbsPath) # Return one path for OO, one path for me.
return uno.systemPathToFileUrl(docAbsPath), docAbsPath
def getResultFilter(self, resultType): def getResultFilter(self, resultType):
if ODT_FILE_TYPES.has_key(resultType): if ODT_FILE_TYPES.has_key(resultType):
res = ODT_FILE_TYPES[resultType] res = ODT_FILE_TYPES[resultType]
@ -76,18 +75,18 @@ class Converter:
ODT_FILE_TYPES.keys())) ODT_FILE_TYPES.keys()))
return res return res
def getResultUrl(self, resultType): def getResultUrl(self, resultType):
baseName = os.path.splitext(self.docUrlStr)[0] import uno
baseName = os.path.splitext(self.docPath)[0]
if resultType != 'odt': if resultType != 'odt':
res = '%s.%s' % (baseName, resultType) res = '%s.%s' % (baseName, resultType)
else: else:
res = '%s.res.%s' % (baseName, resultType) res = '%s.res.%s' % (baseName, resultType)
fileName = res[7:]
try: try:
f = open(fileName, 'w') f = open(res, 'w')
f.write('Hello') f.write('Hello')
f.close() f.close()
os.remove(fileName) os.remove(res)
return res return uno.systemPathToFileUrl(res)
except OSError, oe: except OSError, oe:
raise ConverterError(CANNOT_WRITE_RESULT % (res, oe)) raise ConverterError(CANNOT_WRITE_RESULT % (res, oe))
def connect(self): def connect(self):
@ -166,7 +165,7 @@ class Converter:
except IndexOutOfBoundsException: except IndexOutOfBoundsException:
pass pass
except IllegalArgumentException, iae: except IllegalArgumentException, iae:
raise ConverterError(URL_NOT_FOUND % (self.docUrlStr, iae)) raise ConverterError(URL_NOT_FOUND % (self.docPath, iae))
def convertDocument(self): def convertDocument(self):
if self.resultFilter != 'ODT': if self.resultFilter != 'ODT':
# I must really perform a conversion # I must really perform a conversion