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 = '''
def getTool(self): return self.%s
def getProductConfig(self): return Products.%s.config
def skynView(self):
"""Redirects to skyn/view."""
return self.REQUEST.RESPONSE.redirect(self.getUrl())
'''
# ------------------------------------------------------------------------------
class Generator(AbstractGenerator):

View file

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

View file

@ -328,7 +328,9 @@
<tr tal:define="odd repeat/items/odd;
rhComments items/comments|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']))"
tal:attributes="class string:state-${state}"/>
<td tal:define="actorid python:items.get('actor');

View file

@ -185,12 +185,9 @@ class AbstractWrapper:
self.link(fieldName, ploneObj)
self.o.reindexObject()
# Call custom initialization
try:
if externalData: param = externalData
else: param = True
appyObj.onEdit(param)
except AttributeError:
pass
if hasattr(appyObj, 'onEdit'): appyObj.onEdit(param)
ploneObj.reindexObject()
return appyObj
@ -198,13 +195,16 @@ class AbstractWrapper:
'''Check documentation of self.o.translate.'''
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
programmatically. If p_doAction is False, the action that must
normally be executed after the transition has been triggered will
not be executed. If p_doNotify is False, the notifications
(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
availableTransitions = [t['id'] for t in \
wfTool.getTransitionsFor(self.o)]
@ -222,6 +222,12 @@ class AbstractWrapper:
# (actions, notifications) after the transition has been executed by DC
# workflow.
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)
del self.o._v_appy_do

View file

@ -17,7 +17,7 @@
# 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
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):
self.port = port
self.docUrl = self.getDocUrl(docPath)
self.docUrlStr = unicodedata.normalize('NFKD', self.docUrl).encode(
"ascii", "ignore")
self.docUrl, self.docPath = self.getDocUrls(docPath)
self.resultFilter = self.getResultFilter(resultType)
self.resultUrl = self.getResultUrl(resultType)
self.ooContext = None
self.oo = None # OpenOffice application object
self.doc = None # OpenOffice loaded document
def getDocUrl(self, docPath):
def getDocUrls(self, docPath):
import uno
if not os.path.exists(docPath) and not os.path.isfile(docPath):
raise ConverterError(DOC_NOT_FOUND % 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):
if ODT_FILE_TYPES.has_key(resultType):
res = ODT_FILE_TYPES[resultType]
@ -76,18 +75,18 @@ class Converter:
ODT_FILE_TYPES.keys()))
return res
def getResultUrl(self, resultType):
baseName = os.path.splitext(self.docUrlStr)[0]
import uno
baseName = os.path.splitext(self.docPath)[0]
if resultType != 'odt':
res = '%s.%s' % (baseName, resultType)
else:
res = '%s.res.%s' % (baseName, resultType)
fileName = res[7:]
try:
f = open(fileName, 'w')
f = open(res, 'w')
f.write('Hello')
f.close()
os.remove(fileName)
return res
os.remove(res)
return uno.systemPathToFileUrl(res)
except OSError, oe:
raise ConverterError(CANNOT_WRITE_RESULT % (res, oe))
def connect(self):
@ -166,7 +165,7 @@ class Converter:
except IndexOutOfBoundsException:
pass
except IllegalArgumentException, iae:
raise ConverterError(URL_NOT_FOUND % (self.docUrlStr, iae))
raise ConverterError(URL_NOT_FOUND % (self.docPath, iae))
def convertDocument(self):
if self.resultFilter != 'ODT':
# I must really perform a conversion