From 3258cc10f162b79276c6b547aac3e57d638d4f68 Mon Sep 17 00:00:00 2001
From: Xiaowu Zhang <xiaowu.zhang@nexedi.com>
Date: Mon, 17 Jun 2019 13:30:59 +0000
Subject: [PATCH] erp5_corporate_identity: table reference can be displayed at
 the place where it's defined

---
 .../WebPage_embedReportDocumentList.py           |  2 ++
 .../WebPage_viewAsBook.py                        | 16 +++-------------
 2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/bt5/erp5_corporate_identity/SkinTemplateItem/portal_skins/erp5_corporate_identity/WebPage_embedReportDocumentList.py b/bt5/erp5_corporate_identity/SkinTemplateItem/portal_skins/erp5_corporate_identity/WebPage_embedReportDocumentList.py
index ca49c80059..866b406917 100644
--- a/bt5/erp5_corporate_identity/SkinTemplateItem/portal_skins/erp5_corporate_identity/WebPage_embedReportDocumentList.py
+++ b/bt5/erp5_corporate_identity/SkinTemplateItem/portal_skins/erp5_corporate_identity/WebPage_embedReportDocumentList.py
@@ -45,6 +45,8 @@ if (doc_content.find('${WebPage_')):
   )]
   substitution_list = re.findall(r'\${WebPage_(.*)}', doc_content)
   for substitution_report in substitution_list:
+    if substitution_report == 'insertTableOfReferences':
+      continue
     placeholder = ''.join(['${WebPage_', substitution_report, '}'])
     substitution_content = getReportViaFancyName(substitution_report)
     doc_content = doc_content.replace(placeholder, substitution_content)
diff --git a/bt5/erp5_corporate_identity/SkinTemplateItem/portal_skins/erp5_corporate_identity/WebPage_viewAsBook.py b/bt5/erp5_corporate_identity/SkinTemplateItem/portal_skins/erp5_corporate_identity/WebPage_viewAsBook.py
index 515cfc0b96..8cfa5a3a06 100644
--- a/bt5/erp5_corporate_identity/SkinTemplateItem/portal_skins/erp5_corporate_identity/WebPage_viewAsBook.py
+++ b/bt5/erp5_corporate_identity/SkinTemplateItem/portal_skins/erp5_corporate_identity/WebPage_viewAsBook.py
@@ -89,9 +89,6 @@ book_title = html_quote(override_document_title) if override_document_title else
 if isinstance(book_content, unicode):
   book_content = book_content.encode("UTF-8")
 
-# backcompat
-book_history_section_list = re.findall('<section*?>.+?</section>', book_content, re.S)
-
 # override for tests
 if override_batch_mode:
   book_modification_date = DateTime("1976-11-04")
@@ -129,9 +126,6 @@ book_image_list = []
 book_table_list = []
 book_table_of_content = blank
 
-# backcompat
-book_content = book_content.replace("${WebPage_insertTableOfReferences}", blank)
-
 # XXX: not done
 if book_include_history_table:
   book_signature_list = []
@@ -188,13 +182,9 @@ if book_include_reference_table:
   )
   #if book_format == 'html' or book_format == 'mhtml':
   #  book_references = book_references.encode('UTF-8').strip()
-
-  # backcompat for manual history tables at the beginning of documents
-  # NOTE: assumes <section>s are not used elsewhere!
-  if len(book_history_section_list) > 0:
-    book_content = book_content.replace(book_history_section_list[-1], (book_history_section_list[-1] + book_references.encode('UTF-8').strip()))
-  else:
-    book_content = book_references.encode('UTF-8').strip() + book_content
+  book_content = book_content.replace("${WebPage_insertTableOfReferences}", book_references.encode('UTF-8').strip())
+else:
+  book_content = book_content.replace("${WebPage_insertTableOfReferences}", blank)
 
 # table of content has to be created manually to run over everything that
 # should be indexed in the toc
-- 
2.30.9