Commit 732896c4 authored by Jérome Perrin's avatar Jérome Perrin

corporate_identity: py3

parent aa0101bf
...@@ -266,8 +266,8 @@ if letter_format == "pdf": ...@@ -266,8 +266,8 @@ if letter_format == "pdf":
margin_left=0, margin_left=0,
margin_right=0, margin_right=0,
header_spacing=1, header_spacing=1,
header_html_data=b64encode(header_embedded_html_data), header_html_data=b64encode(header_embedded_html_data).decode(),
footer_html_data=b64encode(footer_embedded_html_data), footer_html_data=b64encode(footer_embedded_html_data).decode(),
) )
) )
......
...@@ -269,10 +269,10 @@ if doc_format == "pdf": ...@@ -269,10 +269,10 @@ if doc_format == "pdf":
margin_bottom=20, margin_bottom=20,
toc=False, toc=False,
before_toc_data_list=before_toc_data_list, before_toc_data_list=before_toc_data_list,
xsl_style_sheet_data=b64encode(xsl_style_sheet_data), xsl_style_sheet_data=b64encode(xsl_style_sheet_data).decode(),
header_html_data=b64encode(header_embedded_html_data), header_html_data=b64encode(header_embedded_html_data).decode(),
header_spacing=10, header_spacing=10,
footer_html_data=b64encode(footer_embedded_html_data), footer_html_data=b64encode(footer_embedded_html_data).decode(),
footer_spacing=3, footer_spacing=3,
) )
default_conversion_kw.update(conversion_dict) default_conversion_kw.update(conversion_dict)
......
...@@ -15,7 +15,7 @@ import re ...@@ -15,7 +15,7 @@ import re
from Products.PythonScripts.standard import html_quote from Products.PythonScripts.standard import html_quote
blank = "" blank = ""
header_current = 1 header_current = '0'
header_initial = None header_initial = None
table_of_content = blank table_of_content = blank
index = 0 index = 0
......
...@@ -10,6 +10,7 @@ Insert reports linked to in a document (including backcompat handling) ...@@ -10,6 +10,7 @@ Insert reports linked to in a document (including backcompat handling)
# doc_format output format being generated # doc_format output format being generated
import re import re
import six
document = context document = context
...@@ -28,10 +29,14 @@ def getReportViaFancyName(my_report_name, follow_up): ...@@ -28,10 +29,14 @@ def getReportViaFancyName(my_report_name, follow_up):
if method_call is not None: if method_call is not None:
# extra curl: Coverage report requires parameter details (1|0) # extra curl: Coverage report requires parameter details (1|0)
if coverage_name: if coverage_name:
return method_call(display_comment=True)[0].encode(encoding='UTF-8') result = method_call(display_comment=True)[0]
if detail_name: elif detail_name:
return method_call(format='detailed',display_detail = 1)[0].encode(encoding='UTF-8') result = method_call(format='detailed',display_detail = 1)[0]
return method_call(display_comment=True)[0].encode(encoding='UTF-8') else:
result = method_call(display_comment=True)[0]
if six.PY2:
result = result.encode(encoding='UTF-8')
return result
if doc_content.find('${WebPage_') != -1: if doc_content.find('${WebPage_') != -1:
document_required_follow_up_list = [x.getObject() for x in document.portal_catalog( document_required_follow_up_list = [x.getObject() for x in document.portal_catalog(
......
...@@ -33,6 +33,7 @@ MAIN FILE: generate book in different output formats ...@@ -33,6 +33,7 @@ MAIN FILE: generate book in different output formats
# display_svg format for svg images (svg, png*) # display_svg format for svg images (svg, png*)
import re import re
import six
from Products.PythonScripts.standard import html_quote from Products.PythonScripts.standard import html_quote
from base64 import b64encode from base64 import b64encode
...@@ -83,8 +84,7 @@ book_version = html_quote(override_document_version) if override_document_versio ...@@ -83,8 +84,7 @@ book_version = html_quote(override_document_version) if override_document_versio
book_description = html_quote(override_document_description) if override_document_description else book.getDescription() book_description = html_quote(override_document_description) if override_document_description else book.getDescription()
book_title = html_quote(override_document_title) if override_document_title else book.getTitle() book_title = html_quote(override_document_title) if override_document_title else book.getTitle()
# unicode if six.PY2 and isinstance(book_content, unicode):
if isinstance(book_content, unicode):
book_content = book_content.encode("UTF-8") book_content = book_content.encode("UTF-8")
# backcompat # backcompat
...@@ -197,7 +197,9 @@ if book_include_reference_table: ...@@ -197,7 +197,9 @@ if book_include_reference_table:
#else: #else:
# book_content = book_content.replace("${WebPage_insertTableOfReferences}", book_references.encode('UTF-8').strip()) # book_content = book_content.replace("${WebPage_insertTableOfReferences}", book_references.encode('UTF-8').strip())
book_references = book.Base_unescape(book_references) book_references = book.Base_unescape(book_references)
book_content = book_content.replace("${WebPage_insertTableOfReferences}", book_references.encode('UTF-8').strip()) if six.PY2:
book_references = book_references.encode('utf-8')
book_content = book_content.replace("${WebPage_insertTableOfReferences}", book_references.strip())
else: else:
book_content = book_content.replace("${WebPage_insertTableOfReferences}", blank) book_content = book_content.replace("${WebPage_insertTableOfReferences}", blank)
...@@ -357,22 +359,22 @@ elif book_format == "pdf": ...@@ -357,22 +359,22 @@ elif book_format == "pdf":
) )
# ================ encode and build cloudoo elements ========================= # ================ encode and build cloudoo elements =========================
header_embedded_html_data = book.Base_convertHtmlToSingleFile(book_head, allow_script=True) header_embedded_html_data = book.Base_convertHtmlToSingleFile(book_head, allow_script=True).encode('utf-8')
before_toc_data_list = [ before_toc_data_list = [
b64encode(book.Base_convertHtmlToSingleFile(book_cover, allow_script=True)), b64encode(book.Base_convertHtmlToSingleFile(book_cover, allow_script=True).encode('utf-8')).decode(),
] ]
after_toc_data_list = [] after_toc_data_list = []
if book_include_history_table: if book_include_history_table:
before_toc_data_list.append( before_toc_data_list.append(
b64encode(book.Base_convertHtmlToSingleFile(book_history, allow_script=True)) b64encode(book.Base_convertHtmlToSingleFile(book_history, allow_script=True).encode('utf-8')).decode()
) )
#if book_include_reference_table: #if book_include_reference_table:
# after_toc_data_list.append( # after_toc_data_list.append(
# b64encode(book.Base_convertHtmlToSingleFile(book_references, allow_script=True)) # b64encode(book.Base_convertHtmlToSingleFile(book_references, allow_script=True).encode('utf-8')).decode()
# ) # )
xsl_style_sheet_data = book_table_of_content xsl_style_sheet_data = book_table_of_content
embedded_html_data = book.Base_convertHtmlToSingleFile(book_content, allow_script=True) embedded_html_data = book.Base_convertHtmlToSingleFile(book_content, allow_script=True).encode('utf-8')
footer_embedded_html_data = book.Base_convertHtmlToSingleFile(book_foot, allow_script=True) footer_embedded_html_data = book.Base_convertHtmlToSingleFile(book_foot, allow_script=True).encode('utf-8')
if margin_15mm: if margin_15mm:
margin_top = 50 margin_top = 50
margin_bottom = 25 margin_bottom = 25
...@@ -385,11 +387,11 @@ elif book_format == "pdf": ...@@ -385,11 +387,11 @@ elif book_format == "pdf":
margin_bottom=margin_bottom, margin_bottom=margin_bottom,
toc=True if book_include_content_table else False, toc=True if book_include_content_table else False,
before_toc_data_list=before_toc_data_list, before_toc_data_list=before_toc_data_list,
xsl_style_sheet_data=b64encode(xsl_style_sheet_data), xsl_style_sheet_data=b64encode(xsl_style_sheet_data).decode(),
after_toc_data_list=after_toc_data_list, after_toc_data_list=after_toc_data_list,
header_html_data=b64encode(header_embedded_html_data), header_html_data=b64encode(header_embedded_html_data).decode(),
header_spacing=10, header_spacing=10,
footer_html_data=b64encode(footer_embedded_html_data), footer_html_data=b64encode(footer_embedded_html_data).decode(),
footer_spacing=3, footer_spacing=3,
) )
) )
......
import re import re
import six
from base64 import b64encode from base64 import b64encode
blank = '' blank = b''
pref = context.getPortalObject().portal_preferences pref = context.getPortalObject().portal_preferences
contract_format = kw.get('format') or 'html' contract_format = kw.get('format') or 'html'
...@@ -35,7 +36,7 @@ contract_version = context.getVersion() or "001" ...@@ -35,7 +36,7 @@ contract_version = context.getVersion() or "001"
contract_description = context.getDescription() contract_description = context.getDescription()
contract_title = context.getTitle() contract_title = context.getTitle()
if isinstance(contract_content, unicode): if six.PY2 and isinstance(contract_content, unicode):
contract_content = contract_content.encode("UTF-8") contract_content = contract_content.encode("UTF-8")
contract_history_section_list = re.findall('<section.+?>.+?</section>', contract_content, re.S) contract_history_section_list = re.findall('<section.+?>.+?</section>', contract_content, re.S)
...@@ -289,22 +290,22 @@ elif contract_format == "pdf": ...@@ -289,22 +290,22 @@ elif contract_format == "pdf":
) )
# ================ encode and build cloudoo elements ========================= # ================ encode and build cloudoo elements =========================
header_embedded_html_data = context.Base_convertHtmlToSingleFile(contract_head, allow_script=True) header_embedded_html_data = context.Base_convertHtmlToSingleFile(contract_head, allow_script=True).encode('utf-8')
before_toc_data_list = [ before_toc_data_list = [
b64encode(context.Base_convertHtmlToSingleFile(contract_cover, allow_script=True)), b64encode(context.Base_convertHtmlToSingleFile(contract_cover, allow_script=True).encode('utf-8')).decode(),
] ]
after_toc_data_list = [] after_toc_data_list = []
if contract_include_history_table: if contract_include_history_table:
before_toc_data_list.append( before_toc_data_list.append(
b64encode(context.Base_convertHtmlToSingleFile(contract_history, allow_script=True)) b64encode(context.Base_convertHtmlToSingleFile(contract_history, allow_script=True).encode('utf-8')).decode()
) )
#if contract_include_reference_table: #if contract_include_reference_table:
# after_toc_data_list.append( # after_toc_data_list.append(
# b64encode(context.Base_convertHtmlToSingleFile(contract_references, allow_script=True)) # b64encode(context.Base_convertHtmlToSingleFile(contract_references, allow_script=True)).decode()
# ) # )
xsl_style_sheet_data = contract_table_of_content xsl_style_sheet_data = contract_table_of_content
embedded_html_data = context.Base_convertHtmlToSingleFile(contract_content, allow_script=True) embedded_html_data = context.Base_convertHtmlToSingleFile(contract_content, allow_script=True).encode('utf-8')
footer_embedded_html_data = context.Base_convertHtmlToSingleFile(contract_foot, allow_script=True) footer_embedded_html_data = context.Base_convertHtmlToSingleFile(contract_foot, allow_script=True).encode('utf-8')
margin_top = 40 margin_top = 40
margin_bottom = 20 margin_bottom = 20
pdf_file = context.Base_cloudoooDocumentConvert(embedded_html_data, "html", "pdf", conversion_kw=dict( pdf_file = context.Base_cloudoooDocumentConvert(embedded_html_data, "html", "pdf", conversion_kw=dict(
...@@ -313,11 +314,11 @@ elif contract_format == "pdf": ...@@ -313,11 +314,11 @@ elif contract_format == "pdf":
margin_bottom=margin_bottom, margin_bottom=margin_bottom,
toc=True if contract_include_content_table else False, toc=True if contract_include_content_table else False,
before_toc_data_list=before_toc_data_list, before_toc_data_list=before_toc_data_list,
xsl_style_sheet_data=b64encode(xsl_style_sheet_data), xsl_style_sheet_data=b64encode(xsl_style_sheet_data).decode(),
after_toc_data_list=after_toc_data_list, after_toc_data_list=after_toc_data_list,
header_html_data=b64encode(header_embedded_html_data), header_html_data=b64encode(header_embedded_html_data).decode(),
header_spacing=10, header_spacing=10,
footer_html_data=b64encode(footer_embedded_html_data), footer_html_data=b64encode(footer_embedded_html_data).decode(),
footer_spacing=3, footer_spacing=3,
) )
) )
......
...@@ -22,6 +22,7 @@ MAIN FILE: render two pager in different output formats ...@@ -22,6 +22,7 @@ MAIN FILE: render two pager in different output formats
# document_save: save file in document module (default None) # document_save: save file in document module (default None)
import re import re
import six
from Products.PythonScripts.standard import html_quote from Products.PythonScripts.standard import html_quote
from base64 import b64encode from base64 import b64encode
...@@ -146,10 +147,11 @@ if leaflet_display_side: ...@@ -146,10 +147,11 @@ if leaflet_display_side:
) )
#leaflet_content = leaflet_legalese.decode() + leaflet_content.decode() #leaflet_content = leaflet_legalese.decode() + leaflet_content.decode()
if isinstance(leaflet_legalese, unicode): if six.PY2:
leaflet_legalese = leaflet_legalese.encode("UTF-8") if isinstance(leaflet_legalese, unicode):
if isinstance(leaflet_content, unicode): leaflet_legalese = leaflet_legalese.encode("UTF-8")
leaflet_content = leaflet_content.encode("UTF-8") if isinstance(leaflet_content, unicode):
leaflet_content = leaflet_content.encode("UTF-8")
leaflet_content = leaflet_legalese + leaflet_content leaflet_content = leaflet_legalese + leaflet_content
...@@ -265,9 +267,9 @@ if leaflet_format == "pdf": ...@@ -265,9 +267,9 @@ if leaflet_format == "pdf":
margin_bottom=20, margin_bottom=20,
margin_left=0, margin_left=0,
margin_right=0, margin_right=0,
header_html_data=b64encode(header_embedded_html_data), header_html_data=b64encode(header_embedded_html_data).decode(),
header_spacing=10, header_spacing=10,
footer_html_data=b64encode(footer_embedded_html_data), footer_html_data=b64encode(footer_embedded_html_data).decode(),
footer_spacing=3 footer_spacing=3
) )
) )
......
...@@ -21,6 +21,7 @@ MAIN FILE: render press release in different output formats ...@@ -21,6 +21,7 @@ MAIN FILE: render press release in different output formats
# document_save: save file in document module (default None) # document_save: save file in document module (default None)
import re import re
import six
from base64 import b64encode from base64 import b64encode
blank = '' blank = ''
...@@ -137,10 +138,11 @@ if release_display_about: ...@@ -137,10 +138,11 @@ if release_display_about:
release_relative_url=release_relative_url, release_relative_url=release_relative_url,
) )
#release_content = release_content.decode() + release_about.decode() #release_content = release_content.decode() + release_about.decode()
if isinstance(release_content, unicode): if six.PY2:
release_content = release_content.encode("UTF-8") if isinstance(release_content, unicode):
if isinstance(release_about, unicode): release_content = release_content.encode("UTF-8")
release_about = release_about.encode("UTF-8") if isinstance(release_about, unicode):
release_about = release_about.encode("UTF-8")
release_content = release_content + release_about release_content = release_content + release_about
...@@ -236,9 +238,9 @@ if release_format == "pdf": ...@@ -236,9 +238,9 @@ if release_format == "pdf":
margin_bottom=20, margin_bottom=20,
margin_left=0, margin_left=0,
margin_right=0, margin_right=0,
header_html_data=b64encode(header_embedded_html_data), header_html_data=b64encode(header_embedded_html_data).decode(),
header_spacing=10, header_spacing=10,
footer_html_data=b64encode(footer_embedded_html_data), footer_html_data=b64encode(footer_embedded_html_data).decode(),
footer_spacing=3 footer_spacing=3
) )
) )
......
...@@ -24,11 +24,12 @@ MAIN FILE: generate presentation in different output formats ...@@ -24,11 +24,12 @@ MAIN FILE: generate presentation in different output formats
# remote_content: convert legacy odp, sxi formats (not active) # remote_content: convert legacy odp, sxi formats (not active)
import re import re
import six
from Products.PythonScripts.standard import html_quote from Products.PythonScripts.standard import html_quote
from base64 import b64encode from base64 import b64encode
blank = '' blank = b''
flags = re.MULTILINE|re.DOTALL|re.IGNORECASE flags = re.MULTILINE|re.DOTALL|re.IGNORECASE
details_separator = '</section><section class="ci-notes-continue"><section><h1>cont.</h1></section>' details_separator = '</section><section class="ci-notes-continue"><section><h1>cont.</h1></section>'
pref = context.getPortalObject().portal_preferences pref = context.getPortalObject().portal_preferences
...@@ -422,15 +423,16 @@ if doc_format == "pdf" or doc_format == "mhtml": ...@@ -422,15 +423,16 @@ if doc_format == "pdf" or doc_format == "mhtml":
# ================ encode and build cloudoo elements ========================= # ================ encode and build cloudoo elements =========================
footer_embedded_html_data = doc.Base_convertHtmlToSingleFile(doc_slideshow_footer, allow_script=True) footer_embedded_html_data = doc.Base_convertHtmlToSingleFile(doc_slideshow_footer, allow_script=True)
#embedded_html_data = doc.Base_convertHtmlToSingleFile(doc_slideshow_content, allow_script=True) #embedded_html_data = doc.Base_convertHtmlToSingleFile(doc_slideshow_content, allow_script=True)
cover = doc.Base_convertHtmlToSingleFile(doc_slideshow_cover, allow_script=True)
before_body_data_list = [ before_body_data_list = [
b64encode(doc.Base_convertHtmlToSingleFile(doc_slideshow_cover, allow_script=True)), b64encode(cover).decode(),
] ]
if doc_format == "mhtml": if doc_format == "mhtml":
context.REQUEST.RESPONSE.setHeader("Content-Type", "text/html;") context.REQUEST.RESPONSE.setHeader("Content-Type", "text/html;")
return doc.Base_convertHtmlToSingleFile(doc_slideshow_cover, allow_script=True) return doc.Base_convertHtmlToSingleFile(doc_slideshow_cover, allow_script=True)
if doc_display_notes: if doc_display_notes:
#after_body_data_list = [ #after_body_data_list = [
# b64encode(doc.Base_convertHtmlToSingleFile(doc_slideshow_notes, allow_script=True)), # b64encode(doc.Base_convertHtmlToSingleFile(doc_slideshow_notes, allow_script=True)).decode(),
#] #]
embedded_html_data = doc.Base_convertHtmlToSingleFile(doc_slideshow_notes, allow_script=True) embedded_html_data = doc.Base_convertHtmlToSingleFile(doc_slideshow_notes, allow_script=True)
after_body_data_list = [] after_body_data_list = []
...@@ -438,7 +440,6 @@ if doc_format == "pdf" or doc_format == "mhtml": ...@@ -438,7 +440,6 @@ if doc_format == "pdf" or doc_format == "mhtml":
embedded_html_data = doc.Base_convertHtmlToSingleFile(doc_slideshow_content, allow_script=True) embedded_html_data = doc.Base_convertHtmlToSingleFile(doc_slideshow_content, allow_script=True)
after_body_data_list = [] after_body_data_list = []
#after_body_data_list = [] #after_body_data_list = []
pdf_file = doc.Base_cloudoooDocumentConvert(embedded_html_data, "html", "pdf", conversion_kw=dict( pdf_file = doc.Base_cloudoooDocumentConvert(embedded_html_data, "html", "pdf", conversion_kw=dict(
encoding="utf8", encoding="utf8",
orientation= "portrait" if doc_display_notes else "landscape", orientation= "portrait" if doc_display_notes else "landscape",
...@@ -447,7 +448,7 @@ if doc_format == "pdf" or doc_format == "mhtml": ...@@ -447,7 +448,7 @@ if doc_format == "pdf" or doc_format == "mhtml":
before_body_data_list=before_body_data_list, before_body_data_list=before_body_data_list,
after_body_data_list=after_body_data_list, after_body_data_list=after_body_data_list,
header_spacing=10, header_spacing=10,
footer_html_data=b64encode(footer_embedded_html_data), footer_html_data=b64encode(footer_embedded_html_data).decode(),
footer_spacing=3 footer_spacing=3
) )
) )
......
import json import json
return ['test report %s' % json.dumps(kw)] return ['test report %s' % json.dumps(kw, sort_keys=True)]
...@@ -206,11 +206,11 @@ class TestCorporateIdentityMethod(ERP5TypeTestCase): ...@@ -206,11 +206,11 @@ class TestCorporateIdentityMethod(ERP5TypeTestCase):
# it has no matter with/without follow up # it has no matter with/without follow up
doc_content = '<div> <a href="sale_opportunity_module/template_test_embed_sale_opportunity?report=Base_generateCorporareIdentityTestReport&amp;test=23"></a> </div>' doc_content = '<div> <a href="sale_opportunity_module/template_test_embed_sale_opportunity?report=Base_generateCorporareIdentityTestReport&amp;test=23"></a> </div>'
output =web_page_with_follow_up.WebPage_embedReportDocumentList(doc_content) output =web_page_with_follow_up.WebPage_embedReportDocumentList(doc_content)
self.assertEqual(output, '<div> test report {"test": "23", "document_language": null, "format": null} </div>') self.assertEqual(output, '<div> test report {"document_language": null, "format": null, "test": "23"} </div>')
doc_content = '<div> <a href="sale_opportunity_module/template_test_embed_sale_opportunity?report=Base_generateCorporareIdentityTestReport&amp;test=23"></a> </div>' doc_content = '<div> <a href="sale_opportunity_module/template_test_embed_sale_opportunity?report=Base_generateCorporareIdentityTestReport&amp;test=23"></a> </div>'
output =web_page_no_follow_up.WebPage_embedReportDocumentList(doc_content) output =web_page_no_follow_up.WebPage_embedReportDocumentList(doc_content)
self.assertEqual(output, '<div> test report {"test": "23", "document_language": null, "format": null} </div>') self.assertEqual(output, '<div> test report {"document_language": null, "format": null, "test": "23"} </div>')
def test_getTemplateProxyParameter_override_person(self): def test_getTemplateProxyParameter_override_person(self):
output_dict_list = self.test_person.Base_getTemplateProxyParameter( output_dict_list = self.test_person.Base_getTemplateProxyParameter(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment