From 715f62ec0b1dae93b0145b81f812f3724bc58a94 Mon Sep 17 00:00:00 2001 From: drfho Date: Wed, 5 Jun 2024 00:19:35 +0200 Subject: [PATCH] fix: docx export (rbz) --- Products/zms/import/docx.metacmd.xml | 37 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/Products/zms/import/docx.metacmd.xml b/Products/zms/import/docx.metacmd.xml index 0086e0d9b..7b72c2949 100644 --- a/Products/zms/import/docx.metacmd.xml +++ b/Products/zms/import/docx.metacmd.xml @@ -12,6 +12,7 @@ import re import shutil import tempfile import urllib +from Products.zms import standard env = {} dpi = 3000 @@ -53,7 +54,7 @@ def process_images(docbookxml): q = pq[1] r = re.compile(p) for f in r.findall(docbookxml): - d = dict(re.findall('\\s(.*?)="(.*?)"',f)) + d = dict(re.findall(r'\s(.*?)="(.*?)"',f)) read_image(d) index = len(images) name = d['src'].split('/')[-1] @@ -190,7 +191,7 @@ regions = { def filter_regions(vtype): # Py-2.7: {k: v for k, v in regions.iteritems() if v['type']==vtype} d = {} - [operator.setitem(d,x,regions[x]) for x in list(region) if regions[x]['type']==vtype] + [operator.setitem(d,x,regions[x]) for x in list(regions) if regions[x]['type']==vtype] return d def process_regions(html,): @@ -294,7 +295,7 @@ def process_paragraphs(html): return docbookxml def html2docbook(html): - r = re.compile('<(.*?)>') + r = re.compile(r'<(.*?)>') for f in r.findall(html): n = f if n.find(' ') > 0: @@ -307,23 +308,23 @@ def html2docbook(html): html = html.replace('<%s>'%f,'') elif regions[n]['type']=='drawing': html = html.replace('<%s>'%f,'[[%s]]'%f) - html = re.sub('((\\S|\\s)*?)<\\/a>','\\1',html) - html = re.sub('','',html) - html = re.sub(' ',' ',html) - html = re.sub('§','§',html) - html = re.sub('&(.*?);','&\\1;',html) + html = re.sub(r'((\S|\s)*?)<\/a>','\\1',html) + html = re.sub(r'','',html) + html = re.sub(r' ',' ',html) + html = re.sub(r'§','§',html) + html = re.sub(r'&(.*?);','&\\1;',html) html = html.replace('\n',' ') html = html.replace('\r',' ') html = html.replace('\t',' ') while html.find(' ')>=0: html = html.replace(' ',' ') - docbookxml = process_paragraphs(html) + docbookxml = process_paragraphs(unicode(html).encode('utf-8')) docbookxml = process_images(docbookxml) return docbookxml def manage_exportDocx( self): request = self.REQUEST - tempfolder = tempfile.mktemp() + tempfolder = tempfile.mkdtemp() request.set('URL',self.absolute_url()) env['self'] = self env['server_url'] = request['SERVER_URL'] @@ -378,13 +379,13 @@ def manage_exportDocx( self): bodyContent = [] bodyContent.append('

%s

'%self.getTitle(request)) bodyContent.append(self.getBodyContent(request)) - bodyContent = ''.join(bodyContent) + bodyContent = ''.join([standard.pystr(s) for s in bodyContent]) document = ''' %s '''%html2docbook(bodyContent) f = open(os.path.join(tempfolder,'word','document.xml'),'w') - f.write(document) + f.write(unicode(document).encode('utf-8')) f.close() # Numbering @@ -437,7 +438,7 @@ def manage_exportDocx( self): 0 - + @@ -446,7 +447,7 @@ def manage_exportDocx( self): - + @@ -479,7 +480,7 @@ def manage_importDocx( self): rc.append(nd) return ''.join(rc).strip() result = [] - tempfolder = tempfile.mktemp() + tempfolder = tempfile.mkdtemp() f = request['file'] filename = os.path.join(tempfolder,f.filename) _fileutil.exportObj(f,filename) @@ -507,12 +508,12 @@ def manage_importDocx( self): html += ''%self.getZMILangStr('ATTR_FILE') html += '
' html += '' - html += '
' + html += '
' html += '
' html += ' '%(self.getZMILangStr('BTN_IMPORT'),self.getZMILangStr('BTN_IMPORT')) html += ' '%(self.getZMILangStr('BTN_EXECUTE'),self.getZMILangStr('BTN_EXECUTE')) html += '
' - html += '
' + html += '
' # --------------------------------- @@ -526,7 +527,7 @@ def manage_importDocx( self):
0 - +