Commit 9a07f26c authored by Sven Franck's avatar Sven Franck

erp5_corporate_identity: fixes for creating letter from event

parent f2bd41c1
......@@ -7,7 +7,7 @@ Create a destination dict for filling templates
# ------------------------------------------------------------------------------
# destination: Can be set if called from Event
# override_destination_person_title: Title of person to use
# override_destination_organisation_title: Title of organisation to use
# override_destination_organisation_title: Title of organisation to use
blank = ''
......@@ -41,7 +41,7 @@ if destination is None:
destination = {}
destination.update(destination_person or {})
destination.update(destination_organisation or {})
# destination => event
else:
destination_uid = context.restrictedTraverse(destination).getUid()
......
......@@ -16,9 +16,10 @@ from Products.PythonScripts.standard import html_quote
# ------------------------------- Set Source ----------------------------------
source_logo_url = None
default_bank_account_uid=context.WebPage_getCustomParameter("default_bank_account_uid")
if source is None:
default_company_title=context.Base_getCustomTemplateParameter("default_company_title")
default_bank_account_uid=context.Base_getCustomTemplateParameter("default_bank_account_uid")
default_company_title=context.WebPage_getCustomParameter("default_company_title")
contributor_title_string = blank
source_person = None
source_person_list = []
......@@ -37,10 +38,13 @@ if source is None:
contributor_title_string = ', '.join(x.get("name", blank) for x in source_person_list)
# source organisation
# order: override => follow-up => default_organisation_uid => default_company_title => source_person career subordinate
if override_source_organisation_title is not None or override_source_organisation_title is blank:
source_organisation_list = context.Base_getCustomTemplateProxyParameter("override_organisation", override_source_organisation_title)
if len(source_organisation_list) == 0:
source_organisation_uid = context.Base_getCustomTemplateParameter("default_source_organisation_uid")
source_organisation_list = context.Base_getCustomTemplateProxyParameter("organisation")
if len(source_organisation_list) == 0:
source_organisation_uid = context.WebPage_getCustomParameter("default_source_organisation_uid")
if source_organisation_uid:
source_organisation_list = context.Base_getCustomTemplateProxyParameter("sender", source_organisation_uid) or []
if len(source_organisation_list) == 0 and default_company_title:
......@@ -51,7 +55,6 @@ if source is None:
if len(organisation_candidate_list) > 0:
source_organisation_list = organisation_candidate_list
break
#source_organisation_list = context.Base_getCustomTemplateProxyParameter("source", source_person.get("uid")) or []
if len(source_organisation_list) > 0:
source_organisation = source_organisation_list[0]
......@@ -62,7 +65,7 @@ if source is None:
# source => event
else:
source_uid =context.restrictedTraverse(source).getUid()
source_uid = context.restrictedTraverse(source).getUid()
source = context.Base_getCustomTemplateProxyParameter("source", source_uid)[0]
# override specific bank account (no default to pick correct one if multiple exist)
......
......@@ -23,12 +23,12 @@ theme_logo_dict = {}
theme_reference = None
theme = (
context.Base_getCustomTemplateProxyParameter("theme") or
context.Base_getCustomTemplateParameter("theme") or
context.Base_getCustomTemplateParameter("default_company_title")
context.WebPage_getCustomParameter("theme") or
context.WebPage_getCustomParameter("default_company_title")
)
if theme is not None:
theme = theme.lower()
theme_logo_prefix = context.Base_getCustomTemplateParameter("default_logo_prefix")
theme_logo_prefix = context.WebPage_getCustomParameter("default_logo_prefix")
if theme_logo_prefix:
theme_reference = theme_logo_prefix + theme.capitalize()
theme_logo_list = context.Base_getCustomTemplateProxyParameter("logo", theme_reference)
......@@ -40,11 +40,11 @@ if theme is None:
theme_dict = {}
theme_dict["theme"] = theme
theme_dict["theme_logo_description"] = theme_logo_dict.get("description", blank)
theme_dict["theme_logo_url"] = context.Base_getCustomTemplateParameter("fallback_image")
theme_dict["theme_logo_url"] = context.WebPage_getCustomParameter("fallback_image")
if theme_logo_dict.get("relative_url", None) is not None:
theme_dict["theme_logo_url"] = theme_logo_dict.get("relative_url") + param
theme_dict["template_css_url"] = css_path + pdf + ".css"
theme_dict["fallback_img_url"] = context.Base_getCustomTemplateParameter("fallback_image") or blank
theme_dict["theme_css_font_list"] = context.Base_getCustomTemplateParameter(font) or []
theme_dict["theme_css_url"] = context.Base_getCustomTemplateParameter(css) or context.Base_getCustomTemplateParameter(css) or blank
theme_dict["fallback_img_url"] = context.WebPage_getCustomParameter("fallback_image") or blank
theme_dict["theme_css_font_list"] = context.WebPage_getCustomParameter(font) or []
theme_dict["theme_css_url"] = context.WebPage_getCustomParameter(css) or context.WebPage_getCustomParameter(css) or blank
return theme_dict
......@@ -59,7 +59,7 @@ doc_requirement_relative_url = kw.get('requirement_relative_url', None)
# -------------------------- Document Parameters ------------------------------
doc_localiser = doc.getPortalObject().Localizer
doc_relative_url = doc.getRelativeUrl()
doc_rendering_fix = doc.Base_getCustomTemplateParameter('wkhtmltopdf_rendering_fix') or blank
doc_rendering_fix = doc.WebPage_getCustomParameter('wkhtmltopdf_rendering_fix') or blank
doc_report = getattr(doc, doc_report_name)
doc_aggregate_list = []
doc_revision = "1"
......
......@@ -8,7 +8,7 @@ Print letter in any of the supported formats
# parameters (*default)
# ------------------------------------------------------------------------------
# REQUEST: request object
# #REQUEST: request object
# format: output format
# portal_skin: skin to use for output
# batch_mode: used for tests
......@@ -26,11 +26,11 @@ Print letter in any of the supported formats
# override_destination_person_title: overide event recipient
# override_date to use instead of current date
new_skin_name = "Letter"
context.getPortalObject().portal_skins.changeSkin(new_skin_name)
if REQUEST is None:
REQUEST = context.REQUEST
REQUEST.set('portal_skin', new_skin_name)
#new_skin_name = "Letter"
#context.getPortalObject().portal_skins.changeSkin(new_skin_name)
#if REQUEST is None:
# REQUEST = context.REQUEST
#REQUEST.set('portal_skin', new_skin_name)
return context.Letter_viewAsLetter(
format=format,
......
......@@ -48,7 +48,6 @@ override_date = letter.Base_setToNone(param=kw.get("override_date", None))
override_batch_mode = letter.Base_setToNone(param=kw.get('batch_mode', None))
# -------------------------- Document Parameters ------------------------------
letter_form = letter.REQUEST
letter_portal_type = letter.getPortalType()
letter_relative_url = letter.getRelativeUrl()
letter_prefix = "Letter."
......@@ -67,26 +66,26 @@ if letter_portal_type == "Web Page":
else:
letter_format = 'pdf'
letter_save = letter_save or True
letter_modification_date = letter_form['start_date'] or None or letter.getCreationDate()
letter_title = letter_form.get('title')
letter_content = letter_form.get('text_content')
letter_modification_date = letter.getStartDate() or letter.getCreationDate()
letter_title = letter.getTitle()
letter_content = letter.getTextContent()
letter_aggregate_list = letter.getAggregateList()
letter_language = letter.Base_setToNone(param=letter_form.get('select_language'))
letter_source = letter_form.get('source') or None
letter_destination = letter_form.get('destination') or None
letter_language = letter.Base_setToNone(param=kw.get('select_language'))
letter_source = letter.getSource()
letter_destination = letter.getDestination()
# cut corner to retrieve path to css files
letter_version = "001"
letter_reference = letter_form.get("reference")
letter_reference = letter.getReference()
# overrides for tests
if override_batch_mode is not None:
if override_batch_mode != None:
letter_modification_date = DateTime("1976-11-04")
if letter_language is not None: #and letter_format == "pdf":
if letter_language != None: #and letter_format == "pdf":
letter.REQUEST['AcceptLanguage'].set(letter_language, 10)
if letter_language is None:
if letter_language == None:
letter_language = blank
if letter_reference is None:
if letter_reference == None:
letter_reference = letter_prefix + letter_title.replace(" ", ".")
letter_full_reference = '-'.join([letter_reference, letter_version, letter_language])
......@@ -141,8 +140,8 @@ if letter_format == "html":
letter_source_company=letter_source.get("corporate_name", letter_source.get("organisation_title", blank)),
letter_source_company_corporate_name=letter_source.get("corporate_name", blank),
letter_source_company_capital=letter_source.get("social_capital", blank),
letter_source_company_capital_currency=letter_source.get("social_capital_currency", letter.Base_getCustomTemplateParameter("default_source_company_capital_currency")),
letter_source_registered_court=letter_source.get("registered_court", letter.Base_getCustomTemplateParameter("default_source_registered_court")),
letter_source_company_capital_currency=letter_source.get("social_capital_currency", letter.WebPage_getCustomParameter("default_source_company_capital_currency")),
letter_source_registered_court=letter_source.get("registered_court", letter.WebPage_getCustomParameter("default_source_registered_court")),
letter_source_ape_code=letter_source.get("activity_code", blank),
letter_source_address=letter_source.get("address", blank),
letter_source_postal_code=letter_source.get("postal_code", blank),
......@@ -226,8 +225,8 @@ if letter_format == "pdf":
letter_source_company=letter_source.get("organisation_title", blank),
letter_source_company_corporate_name=letter_source.get("corporate_name", blank),
letter_source_company_capital=letter_source.get("social_capital", blank),
letter_source_company_capital_currency=letter_source.get("social_capital_currency", letter.Base_getCustomTemplateParameter("default_source_company_capital_currency")),
letter_source_registered_court=letter_source.get("registered_court", letter.Base_getCustomTemplateParameter("default_source_registered_court")),
letter_source_company_capital_currency=letter_source.get("social_capital_currency", letter.WebPage_getCustomParameter("default_source_company_capital_currency")),
letter_source_registered_court=letter_source.get("registered_court", letter.WebPage_getCustomParameter("default_source_registered_court")),
letter_source_ape_code=letter_source.get("activity_code", blank),
letter_source_address=letter_source.get("address", blank),
letter_source_postal_code=letter_source.get("postal_code", blank),
......@@ -260,6 +259,11 @@ if letter_format == "pdf":
)
)
# return file for comparison in portal-component tests
if override_batch_mode != None:
if letter_portal_type != "Web Page":
return pdf_file
return letter.WebPage_finishPdfCreation(
doc_download=letter_download,
doc_save=letter_save,
......
......@@ -224,10 +224,23 @@ if pass_parameter is not None and pass_source_data is not None:
# -------------- Source/Destination (Person => Organisation) -----------------
# returns [{organisation_dict}]
if pass_parameter == "source" or pass_parameter == "destination":
for c in portal_object.person_module.searchFolder(uid=pass_source_data):
organisation = c.getCareerSubordinationValue()
if organisation is not None:
return populateOrganisationDict([organisation])
person_candidate_list = portal_object.person_module.searchFolder(uid=pass_source_data)
organisation_candidate_list = portal_object.organisation_module.searchFolder(uid=pass_source_data)
if len(person_candidate_list) > 0:
for c in person_candidate_list:
organisation = c.getCareerSubordinationValue()
if organisation is not None:
return populateOrganisationDict([organisation])
else:
return populatePersonDict([c])
# events might pass organisation as sender/recipient
if len(organisation_candidate_list) > 0:
organisation_candidate_list = portal_object.organisation_module.searchFolder(uid=pass_source_data)
for o in organisation_candidate_list:
return populateOrganisationDict([o])
return []
# -------------------- Organisation (Follow-Up) ------------------------------
......
......@@ -75,7 +75,7 @@ override_batch_mode = book.Base_setToNone(param=kw.get('batch_mode', None))
book_localiser = book.getPortalObject().Localizer
book_relative_url = book.getRelativeUrl()
book_prefix = "Book."
book_rendering_fix = book.Base_getCustomTemplateParameter('wkhtmltopdf_rendering_fix') or blank
book_rendering_fix = book.WebPage_getCustomParameter('wkhtmltopdf_rendering_fix') or blank
book_content = book.getTextContent()
book_aggregate_list = []
book_revision = book.getRevision()
......
......@@ -4,7 +4,7 @@
/* ------------------------ Slideshow -------------------------------------- */
.ci-default .ci-slideshow .ci-slideshow-header h2,
.ci-default .ci-slideshow .ci-slideshow-footer,
.ci-default .ci-slideshow .ci-slideshow-footer,
.ci-default .ci-slideshow .ci-slideshow-intro.present > h2,
.ci-default .ci-slideshow .ci-slideshow-intro.present:before,
.ci-default .ci-slideshow h1,
......@@ -81,7 +81,7 @@
color: #ffffff;
}
.ci-default .ci-letter .ci-letter-footer {
border-color: #C3C7C6;
border-color: #C3C7C6;
}
.ci-default .ci-letter .ci-letter-bar-logo img {
background: #ffffff;
......
......@@ -92,6 +92,16 @@ class TestCorporateIdentityTemplates(ERP5TypeTestCase):
self.portal.portal_preferences.default_nexedi_system_preference.enable()
self.tic()
def createTestEvent(self, target_language):
test_event = self.portal.event_module.newContent(
portal_type="Letter",
language=target_language,
content_type="text/html",
text_content="Hello",
title="Test"
)
return test_event
def computeImageRenderingRootMeanSquare(self, image_data_1, image_data_2):
"""
Compute and return the RMS (Root Mean Square) of image_data_1 and 2.
......@@ -112,10 +122,7 @@ class TestCorporateIdentityTemplates(ERP5TypeTestCase):
# image can be converted into greyscale without transparency
h1 = image1.histogram()
h2 = image2.histogram()
rms = math.sqrt(
#reduce(operator.add, map(lambda a, b: (a - b) ** 2, h1, h2)) / len(h1)
sum((a - b) ** 2 for a, b in zip(h1, h2)) / len(h1)
)
rms = math.sqrt(sum((a - b) ** 2 for a, b in zip(h1, h2)) / len(h1))
# Note:
# - rms is ~5300.0 same page, bmp without alpha and bmp transparent back
......@@ -183,7 +190,6 @@ class TestCorporateIdentityTemplates(ERP5TypeTestCase):
if has_original_accept_language:
self.app.REQUEST["AcceptLanguage"] = original_accept_language
else:
# `del self.app.REQUEST["AcceptLanguage"]` raises `AttributeError: __delitem__`
self.app.REQUEST["AcceptLanguage"] = AcceptLanguage()
def callWithNewRequestForm(self, *args, **kw):
......@@ -230,16 +236,21 @@ class TestCorporateIdentityTemplates(ERP5TypeTestCase):
"""
Compare a rendered PDF page with a a pregenerated image
"""
test_page = getattr(self.portal.web_page_module, id1)
target_language=kw.get("lang", None) or "en"
expected_image = getattr(self.portal.image_module, id2)
image_source_pdf_doc = getattr(self.portal.document_module, id3)
dump = getattr(self.portal, 'dump_data', None)
kw["batch_mode"] = 1
if id1 == None:
test_page = self.createTestEvent(target_language)
self.tic()
else:
test_page = getattr(self.portal.web_page_module, id1)
pdf_kw = dict(
reference=test_page.getReference(),
target_language=kw.get("lang", None) or "en",
version=test_page.getVersion(),
target_language=target_language
)
pdf_data = self.call(
......@@ -251,7 +262,6 @@ class TestCorporateIdentityTemplates(ERP5TypeTestCase):
**kw
)
# XXX don't overwrite file to create image, use temporary-pdf?
image_source_pdf_doc.setData(pdf_data)
_, bmp = image_source_pdf_doc.convert("bmp", frame=kw.get("page_number"))
......@@ -680,7 +690,7 @@ class TestCorporateIdentityTemplates(ERP5TypeTestCase):
use_skin="Letter",
override_source_organisation_title="Test Association",
override_source_person_title="Test Association Member",
override_destination_organisation_title="Test Associatino",
override_destination_organisation_title="Test Association",
override_destination_person_title="Test Association Member",
subfield_field_override_date_year="1999",
subfield_field_override_date_month="12",
......@@ -688,6 +698,56 @@ class TestCorporateIdentityTemplates(ERP5TypeTestCase):
)
)
@changeSkin('Letter')
def test_pdfLetterEventOverrideSenderRecipientOrganisation(self):
"""
Test:
- Event as Letter
- override recipient, sender and use organisations
- export as pdf
"""
self.runPdfTestPattern(
None,
"template_test_letter_input_page_0_005_en_bmp",
"template_test_letter_input_005_en_pdf",
**dict(
page_number=0,
test_method="Letter_send",
format="pdf",
use_skin="Letter",
override_source_organisation_title="Test Organisation",
override_destination_organisation_title="Test Organisation",
subfield_field_override_date_year="1999",
subfield_field_override_date_month="12",
subfield_field_override_date_day="31"
)
)
@changeSkin('Letter')
def test_pdfLetterEventOverrideSenderRecipientPerson(self):
"""
Test:
- Event as Letter
- override recipient, sender and a person without any organisation
- export as pdf
"""
self.runPdfTestPattern(
None,
"template_test_letter_input_page_0_006_en_bmp",
"template_test_letter_input_006_en_pdf",
**dict(
page_number=0,
test_method="Letter_send",
format="pdf",
use_skin="Letter",
override_source_person_title="Test Unassociated Member",
override_destination_person_title="Test Unassociated Member",
subfield_field_override_date_year="1999",
subfield_field_override_date_month="12",
subfield_field_override_date_day="31"
)
)
@changeSkin('Letter')
def test_pdfLetterLocaliserHeadDisplay(self):
"""
......
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