Commit a927c92b authored by Sven Franck's avatar Sven Franck

erp5_corporate_identity: rename parameter getters and add letter preview

parent 71e32c0a
"""
================================================================================
Lookup a (hardcoded) custom parameter (default image, css-path etc)
================================================================================
"""
# parameters:
# ------------------------------------------------------------------------------
# parameter Parameter to lookup
# override_data Portal Type or relative url passed along
customProxyHandler = getattr(context, "WebPage_getCustomProxyParameter", None)
if customProxyHandler != None:
source_data = override_data or context.getUid()
return customProxyHandler(parameter=parameter, source_data=source_data)
......@@ -22,19 +22,19 @@ if destination == None:
# destination person
if override_destination_person_title != None or override_destination_person_title == blank:
destination_person_list = context.Base_getCustomTemplateProxyParameter("override_person", override_destination_person_title)
destination_person_list = context.Base_getTemplateProxyParameter(parameter="override_person", source_data=override_destination_person_title)
if len(destination_person_list) == 0:
destination_person_list = context.Base_getCustomTemplateProxyParameter("person", None)
destination_person_list = context.Base_getTemplateProxyParameter(parameter="person", source_data=None)
if len(destination_person_list) > 0:
destination_person = destination_person_list[0]
# destination organisation
if override_destination_organisation_title != None or override_destination_organisation_title == blank:
destination_organisation_list = context.Base_getCustomTemplateProxyParameter("override_organisation", override_destination_organisation_title)
destination_organisation_list = context.Base_getTemplateProxyParameter(parameter="override_organisation", source_data=override_destination_organisation_title)
if len(destination_organisation_list) == 0:
destination_organisation_list = context.Base_getCustomTemplateProxyParameter("organisation", None)
destination_organisation_list = context.Base_getTemplateProxyParameter(parameter="organisation", source_data=None)
if len(destination_organisation_list) == 0 and destination_person != None:
destination_organisation_list = context.Base_getCustomTemplateProxyParameter("source", destination_person.get("uid")) or []
destination_organisation_list = context.Base_getTemplateProxyParameter(parameter="source", source_data=destination_person.get("uid")) or []
if len(destination_organisation_list) > 0:
destination_organisation = destination_organisation_list[0]
......@@ -45,6 +45,6 @@ if destination == None:
# destination => event
else:
destination_uid = context.restrictedTraverse(destination).getUid()
destination = context.Base_getCustomTemplateProxyParameter("destination", destination_uid)[0]
destination = context.Base_getTemplateProxyParameter(parameter="destination", source_data=destination_uid)[0]
return destination
......@@ -16,10 +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")
default_bank_account_uid=context.Base_getTemplateParameter("default_bank_account_uid")
if source == None:
default_company_title=context.WebPage_getCustomParameter("default_company_title")
default_company_title=context.Base_getTemplateParameter("default_company_title")
contributor_title_string = blank
source_person = None
source_person_list = []
......@@ -30,9 +30,9 @@ if source == None:
# source person
if override_source_person_title != None or override_source_person_title == blank:
source_person_list = context.Base_getCustomTemplateProxyParameter("override_person", override_source_person_title)
source_person_list = context.Base_getTemplateProxyParameter(parameter="override_person", source_data=override_source_person_title)
if len(source_person_list) == 0:
source_person_list = context.Base_getCustomTemplateProxyParameter("author", None) or []
source_person_list = context.Base_getTemplateProxyParameter(parameter="author", source_data=None) or []
if len(source_person_list) > 0:
source_person = source_person_list[0]
contributor_title_string = ', '.join(x.get("name", blank) for x in source_person_list)
......@@ -40,18 +40,18 @@ if source == None:
# source organisation
# order: override => follow-up => default_organisation_uid => default_company_title => source_person career subordinate
if override_source_organisation_title != None or override_source_organisation_title == blank:
source_organisation_list = context.Base_getCustomTemplateProxyParameter("override_organisation", override_source_organisation_title)
source_organisation_list = context.Base_getTemplateProxyParameter(parameter="override_organisation", source_data=override_source_organisation_title)
if len(source_organisation_list) == 0:
source_organisation_list = context.Base_getCustomTemplateProxyParameter("organisation")
source_organisation_list = context.Base_getTemplateProxyParameter(parameter="organisation", source_data=None)
if len(source_organisation_list) == 0:
source_organisation_uid = context.WebPage_getCustomParameter("default_source_organisation_uid")
source_organisation_uid = context.Base_getTemplateParameter("default_source_organisation_uid")
if source_organisation_uid:
source_organisation_list = context.Base_getCustomTemplateProxyParameter("sender", source_organisation_uid) or []
source_organisation_list = context.Base_getTemplateProxyParameter(parameter="sender", source_data=source_organisation_uid) or []
if len(source_organisation_list) == 0 and default_company_title:
source_organisation_list = context.Base_getCustomTemplateProxyParameter("override_organisation", default_company_title) or []
source_organisation_list = context.Base_getTemplateProxyParameter(parameter="override_organisation", source_data=default_company_title) or []
if len(source_organisation_list) == 0 and source_person != None:
for organisation_candidate in source_person_list:
organisation_candidate_list = context.Base_getCustomTemplateProxyParameter("source", organisation_candidate.get("uid")) or []
organisation_candidate_list = context.Base_getTemplateProxyParameter(parameter="source", source_data=organisation_candidate.get("uid")) or []
if len(organisation_candidate_list) > 0:
source_organisation_list = organisation_candidate_list
break
......@@ -66,17 +66,23 @@ if source == None:
# source => event
else:
source_uid = context.restrictedTraverse(source).getUid()
source = context.Base_getCustomTemplateProxyParameter("source", source_uid)[0]
source = context.Base_getTemplateProxyParameter(parameter="source", source_data=source_uid)[0]
# override specific bank account (no default to pick correct one if multiple exist)
if default_bank_account_uid != None:
override_bank_account_list = context.Base_getCustomTemplateProxyParameter("bank", default_bank_account_uid) or []
override_bank_account_list = context.Base_getTemplateProxyParameter(parameter="bank", source_data=default_bank_account_uid) or []
if len(override_bank_account_list) > 0:
override_bank_account = override_bank_account_list[0]
source["bank"] = override_bank_account.get("bank")
source["bic"] = override_bank_account.get("bic")
source["iban"] = override_bank_account.get("iban")
# social capital currency and registered court fallbacks
if source.get("social_capital_currency") is blank:
source["social_capital_currency"] = context.Base_getTemplateParameter("default_source_company_capital_currency")
if source.get("corporate_registration_code") is blank:
source["corporate_registration_code"] = context.Base_getTemplateParameter("default_source_registered_court")
# XXX images stored on organisation (as do images in skin folders)
if override_logo_reference:
source_logo_url = html_quote(override_logo_reference) + "?format=png"
......
......@@ -54,7 +54,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>WebPage_getCustomParameter</string> </value>
<value> <string>Base_getTemplateParameter</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -178,14 +178,14 @@ def getSubstringFromProduct(my_candidate, my_as_is):
return software_title.split(software_match_string)[0].lower()
def callSelf(my_parameter, my_source_id, my_flag_site):
return context.WebPage_getCustomProxyParameter(
return context.Base_getTemplateProxyParameter(
parameter=my_parameter,
source_uid=my_source_id,
flag_site=my_flag_site
)
pass_parameter = kw.get("parameter", None)
pass_source_data = kw.get("source_data", None)
pass_source_data = kw.get("source_data", None) or context.getUid()
pass_flag_site = kw.get("flag_site", None)
if pass_parameter != None and pass_source_data != None:
......
......@@ -62,7 +62,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>WebPage_getCustomProxyParameter</string> </value>
<value> <string>Base_getTemplateProxyParameter</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -22,16 +22,16 @@ theme_logo_list = []
theme_logo_dict = {}
theme_reference = None
theme = (
context.Base_getCustomTemplateProxyParameter("theme") or
context.WebPage_getCustomParameter("theme") or
context.WebPage_getCustomParameter("default_company_title")
context.Base_getTemplateProxyParameter(parameter="theme", source_data=None) or
context.Base_getTemplateParameter("theme") or
context.Base_getTemplateParameter("default_company_title")
)
if theme != None:
theme = theme.lower()
theme_logo_prefix = context.WebPage_getCustomParameter("default_logo_prefix")
theme_logo_prefix = context.Base_getTemplateParameter("default_logo_prefix")
if theme_logo_prefix:
theme_reference = theme_logo_prefix + theme.capitalize()
theme_logo_list = context.Base_getCustomTemplateProxyParameter("logo", theme_reference)
theme_logo_list = context.Base_getTemplateProxyParameter(parameter="logo", source_data=theme_reference)
if len(theme_logo_list) > 0:
theme_logo_dict = theme_logo_list[0]
if theme == None:
......@@ -40,11 +40,11 @@ if theme == None:
theme_dict = {}
theme_dict["theme"] = theme
theme_dict["theme_logo_description"] = theme_logo_dict.get("description", blank)
theme_dict["theme_logo_url"] = context.WebPage_getCustomParameter("fallback_image")
theme_dict["theme_logo_url"] = context.Base_getTemplateParameter("fallback_image")
if theme_logo_dict.get("relative_url", None) != 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.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
theme_dict["fallback_img_url"] = context.Base_getTemplateParameter("fallback_image") or blank
theme_dict["theme_css_font_list"] = context.Base_getTemplateParameter(font) or []
theme_dict["theme_css_url"] = context.Base_getTemplateParameter(css) or context.Base_getTemplateParameter(css) or blank
return theme_dict
......@@ -50,11 +50,11 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>parameter=None, override_data=None</string> </value>
<value> <string>*args,**kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getCustomTemplateProxyParameter</string> </value>
<value> <string>Base_viewAsLetter</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -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.WebPage_getCustomParameter('wkhtmltopdf_rendering_fix') or blank
doc_rendering_fix = doc.Base_getTemplateParameter('wkhtmltopdf_rendering_fix') or blank
doc_report = getattr(doc, doc_report_name)
doc_aggregate_list = []
doc_revision = "1"
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>*args,**kw</string> </value>
<value> <string>format=None, display_source_address=None, display_head=None, display_svg=None, batch_mode=False, document_download=None, document_save=None, override_source_organisation_title=None,override_source_person_title=None,override_destination_organisation_title=None,override_destination_person_title=None,override_date=None,**kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>default</string>
<string>description</string>
<string>gadget_url</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>content</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>gadget_url</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_iframe_gadget_field</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>gadget_url</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Content</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: context.Base_getRelevantContext(context_url=context.getRelativeUrl()).getData().encode("base64")</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: field.restrictedTraverse(\'pdf_js/pdfjs.gadget.html\').absolute_url() + "?auto_focus=1"</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>css_class</string>
<string>description</string>
<string>display_width</string>
<string>editable</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>document_title</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>css_class</string> </key>
<value> <string>headline</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>The title is display as main content title and page title.</string> </value>
</item>
<item>
<key> <string>display_width</string> </key>
<value> <int>40</int> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_event_title</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewCRMFieldLibrary</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -25,7 +25,7 @@ Export this web page as letter in specified format
# override_destination_person_title: overide event recipient
# override_date to use instead of current date
return context.Letter_viewAsLetter(
return context.WebPage_viewAsLetter(
format=format,
display_head=display_head,
display_svg=display_svg,
......
......@@ -24,7 +24,7 @@ Print letter in any of the supported formats
# override_destination_person_title: overide event recipient
# override_date to use instead of current date
return context.Letter_viewAsLetter(
return context.WebPage_viewAsLetter(
format=format,
display_head=display_head,
display_svg=display_svg,
......
......@@ -12,17 +12,17 @@ Upgrade image for the specific type of display
# img_svg_format display image as svg (default png/None)
import re
from OFS.Traversable import NotFound
from zExceptions import NotFound
if img_string == None or img_string == "":
return img_string
img_src = re.findall("src=['\"](.*?)['\"]", img_string)[0]
img_obj = context.restrictedTraverse(img_src.split("?")[0])
img_obj = context.restrictedTraverse(img_src.split("?")[0], None)
img_type = img_obj.getContentType()
# flag broken link until further notice
if img_obj is None:
if img_obj == None:
raise NotFound('The following image could not be found in erp5: %s' % (img_src.split("?")[0]))
# ensure alt attributes are set
......
......@@ -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.WebPage_getCustomParameter('wkhtmltopdf_rendering_fix') or blank
book_rendering_fix = book.Base_getTemplateParameter('wkhtmltopdf_rendering_fix') or blank
book_content = book.getTextContent()
book_aggregate_list = []
book_revision = book.getRevision()
......
"""
================================================================================
View a WebPage as Letter in the defined output format
================================================================================
"""
# ERP5 web uses format= argument, which is also a python builtin
# pylint: disable=redefined-builtin
# parameters (*default)
# ------------------------------------------------------------------------------
# format: output format
# batch_mode: used for tests
# display_source_address display source (!) adress in adress field or not*
# display_svg display images in svg or png*
# display_head display letter adress head (1)* or not (0)
# document_download: download file directly (default None)
# document_save: save file in document module (default None)
# override_source_organisation_title: override event sender career subordinate
# override_source_person_title: override event sender title
# override_destination_organisation_title: override event recipient subordinate
# override_destination_person_title: overide event recipient
# override_date to use instead of current date
return context.Base_viewAsLetter(
format=format,
display_head=display_head,
display_svg=display_svg,
display_source_address=display_source_address,
override_source_organisation_title=override_source_organisation_title,
override_source_person_title=override_source_person_title,
override_destination_organisation_title=override_destination_organisation_title,
override_destination_person_title=override_destination_person_title,
override_date=override_date,
document_save=document_save,
document_download=document_download,
batch_mode=batch_mode,
**kw
)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>format=None, display_source_address=None, display_head=None, display_svg=None, batch_mode=False, document_download=None, document_save=None, override_source_organisation_title=None,override_source_person_title=None,override_destination_organisation_title=None,override_destination_person_title=None,override_date=None,**kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>WebPage_viewAsLetter</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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