Commit 1b31fcbd authored by Jérome Perrin's avatar Jérome Perrin

Improve Developer experience (mostly ERP5 Workflow/Python Scripts)

Fixes [#20210517-960A47](https://erp5js.nexedi.net/#/bug_module/20210517-960A47)

The most important changes are:
 - coding style is enabled again for workflow scripts and starts to be enabled for ERP5 Python scripts
 - monaco editor support for workflow scripts, SQL methods and .less
 - small fixes for python/workflow scripts forms and ZMI

See merge request nexedi/erp5!1422
parents 015bc1c1 b1f36ffd
...@@ -10,11 +10,9 @@ The test operates on 'today' transactions. ...@@ -10,11 +10,9 @@ The test operates on 'today' transactions.
from DateTime import DateTime from DateTime import DateTime
portal = context.getPortalObject() portal = context.getPortalObject()
accounting_module = portal.accounting_module
account_module = portal.account_module account_module = portal.account_module
ledger = portal.portal_categories.ledger ledger = portal.portal_categories.ledger
organisation_module = portal.organisation_module organisation_module = portal.organisation_module
person_module = portal.person_module
one_hour = 1.0 / 24.0 one_hour = 1.0 / 24.0
now = DateTime() now = DateTime()
...@@ -26,12 +24,14 @@ if with_ledger: ...@@ -26,12 +24,14 @@ if with_ledger:
accounting_ledger = ledger.get('accounting', None) accounting_ledger = ledger.get('accounting', None)
if accounting_ledger is None: if accounting_ledger is None:
accounting_ledger = ledger.newContent(portal_type='Category', id='accounting') accounting_ledger = ledger.newContent(portal_type='Category',
id='accounting')
for sub_category_name in ('general', 'detailed'): for sub_category_name in ('general', 'detailed'):
sub_category = accounting_ledger.get(sub_category_name, None) sub_category = accounting_ledger.get(sub_category_name, None)
if sub_category is None: if sub_category is None:
sub_category = accounting_ledger.newContent(portal_type='Category', id=sub_category_name) sub_category = accounting_ledger.newContent(portal_type='Category',
id=sub_category_name)
# necessary for the "ledger" form field to appear and have correct options # necessary for the "ledger" form field to appear and have correct options
accounting_transaction = portal.portal_types.get('Accounting Transaction') accounting_transaction = portal.portal_types.get('Accounting Transaction')
...@@ -59,8 +59,7 @@ context.AccountingTransactionModule_createAccountingTestDocument( ...@@ -59,8 +59,7 @@ context.AccountingTransactionModule_createAccountingTestDocument(
dict(portal_type='Accounting Transaction Line', dict(portal_type='Accounting Transaction Line',
source_value=account_module.goods_sales, source_value=account_module.goods_sales,
source_credit=100.0)), source_credit=100.0)),
**extra_kwargs_general **extra_kwargs_general)
)
context.AccountingTransactionModule_createAccountingTestDocument( context.AccountingTransactionModule_createAccountingTestDocument(
portal_type='Accounting Transaction', portal_type='Accounting Transaction',
...@@ -70,12 +69,12 @@ context.AccountingTransactionModule_createAccountingTestDocument( ...@@ -70,12 +69,12 @@ context.AccountingTransactionModule_createAccountingTestDocument(
destination_section_value=organisation_module.client_1, destination_section_value=organisation_module.client_1,
start_date=today + 2 * one_hour, start_date=today + 2 * one_hour,
embedded=(dict(portal_type='Accounting Transaction Line', embedded=(dict(portal_type='Accounting Transaction Line',
source_value=account_module.payable, source_debit=200.0), source_value=account_module.payable,
source_debit=200.0),
dict(portal_type='Accounting Transaction Line', dict(portal_type='Accounting Transaction Line',
source_value=account_module.goods_sales, source_value=account_module.goods_sales,
source_credit=200.0)), source_credit=200.0)),
**extra_kwargs_general **extra_kwargs_general)
)
if with_ledger: if with_ledger:
context.AccountingTransactionModule_createAccountingTestDocument( context.AccountingTransactionModule_createAccountingTestDocument(
...@@ -86,9 +85,9 @@ if with_ledger: ...@@ -86,9 +85,9 @@ if with_ledger:
destination_section_value=organisation_module.client_1, destination_section_value=organisation_module.client_1,
start_date=today + 3 * one_hour, start_date=today + 3 * one_hour,
embedded=(dict(portal_type='Accounting Transaction Line', embedded=(dict(portal_type='Accounting Transaction Line',
source_value=account_module.payable, source_debit=400.0), source_value=account_module.payable,
source_debit=400.0),
dict(portal_type='Accounting Transaction Line', dict(portal_type='Accounting Transaction Line',
source_value=account_module.goods_sales, source_value=account_module.goods_sales,
source_credit=400.0)), source_credit=400.0)),
**extra_kwargs_detailed **extra_kwargs_detailed)
)
...@@ -94,8 +94,11 @@ ...@@ -94,8 +94,11 @@
model_language = 'javascript'; model_language = 'javascript';
} else if (options.portal_type === 'Web Style') { } else if (options.portal_type === 'Web Style') {
model_language = 'css'; model_language = 'css';
} else if (options.portal_type === 'SQL Method') {
model_language = 'sql';
} else if ( } else if (
options.portal_type === 'Python Script' || options.portal_type === 'Python Script' ||
options.portal_type === 'Workflow Script' ||
options.portal_type === 'Test Component' || options.portal_type === 'Test Component' ||
options.portal_type === 'Extension Component' || options.portal_type === 'Extension Component' ||
options.portal_type === 'Document Component' || options.portal_type === 'Document Component' ||
......
...@@ -77,9 +77,10 @@ class PythonScript(XMLObject, ZopePythonScript, ExpressionMixin('expression')): ...@@ -77,9 +77,10 @@ class PythonScript(XMLObject, ZopePythonScript, ExpressionMixin('expression')):
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
#View content list, Force /view, Standart option in python scripts #View content list, Force /view, Standart option in python scripts
manage_options = ( XMLObject.manage_options[0], manage_options = ( ZopePythonScript.manage_options[0],
{'icon':'', 'label':'View','action':'view'}) \ {'icon':'', 'label':'View','action':'view'}) \
+ ZopePythonScript.manage_options + ( XMLObject.manage_options[0], ) \
+ ZopePythonScript.manage_options[1:]
# Declarative properties # Declarative properties
property_sheets = ( PropertySheet.Base property_sheets = ( PropertySheet.Base
......
...@@ -27,9 +27,7 @@ ...@@ -27,9 +27,7 @@
</item> </item>
<item> <item>
<key> <string>content_icon</string> </key> <key> <string>content_icon</string> </key>
<value> <value> <string>/misc_/PythonScripts/pyscript.gif</string> </value>
<none/>
</value>
</item> </item>
<item> <item>
<key> <string>description</string> </key> <key> <string>description</string> </key>
...@@ -65,6 +63,18 @@ ...@@ -65,6 +63,18 @@
<key> <string>type_class</string> </key> <key> <string>type_class</string> </key>
<value> <string>PythonScript</string> </value> <value> <string>PythonScript</string> </value>
</item> </item>
<item>
<key> <string>type_interface</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>type_mixin</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
......
...@@ -8,9 +8,7 @@ ...@@ -8,9 +8,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>content_icon</string> </key> <key> <string>content_icon</string> </key>
<value> <value> <string>/misc_/PythonScripts/pyscript.gif</string> </value>
<none/>
</value>
</item> </item>
<item> <item>
<key> <string>description</string> </key> <key> <string>description</string> </key>
......
...@@ -61,7 +61,7 @@ def checkPythonScript(script_instance, script_path): ...@@ -61,7 +61,7 @@ def checkPythonScript(script_instance, script_path):
Message( Message(
location="{script_path}:{row}:{column}".format(**annotation), location="{script_path}:{row}:{column}".format(**annotation),
message=annotation['text'], message=annotation['text'],
edit_url="{script_path}/manage_main?line={row}".format(**annotation),)) edit_url="{script_path}/manage_workspace?line={row}".format(**annotation),))
def checkComponent(component_instance): def checkComponent(component_instance):
"""Check a component, adding messages to global `line_list` """Check a component, adding messages to global `line_list`
...@@ -93,9 +93,11 @@ for workflow_id in context.getTemplateWorkflowIdList(): ...@@ -93,9 +93,11 @@ for workflow_id in context.getTemplateWorkflowIdList():
for script_container in script_container_list: for script_container in script_container_list:
for script_path, script_instance in portal.ZopeFind( for script_path, script_instance in portal.ZopeFind(
script_container, script_container, obj_metatypes=[
obj_metatypes=['Script (Python)'], 'Script (Python)',
search_sub=1): 'ERP5 Python Script',
'ERP5 Workflow Script',
], search_sub=1):
checkPythonScript(script_instance, "%s/%s" % ( checkPythonScript(script_instance, "%s/%s" % (
portal.portal_url.getRelativeUrl(script_container), script_path)) portal.portal_url.getRelativeUrl(script_container), script_path))
......
...@@ -85,8 +85,8 @@ ...@@ -85,8 +85,8 @@
<list> <list>
<string>my_parameter_signature</string> <string>my_parameter_signature</string>
<string>my_description</string> <string>my_description</string>
<string>error_message</string> <string>your_error_message</string>
<string>warning_message</string> <string>your_warning_message</string>
</list> </list>
</value> </value>
</item> </item>
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>error_message</string> </value> <value> <string>your_error_message</string> </value>
</item> </item>
<item> <item>
<key> <string>message_values</string> </key> <key> <string>message_values</string> </key>
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>warning_message</string> </value> <value> <string>your_warning_message</string> </value>
</item> </item>
<item> <item>
<key> <string>message_values</string> </key> <key> <string>message_values</string> </key>
...@@ -62,10 +62,6 @@ ...@@ -62,10 +62,6 @@
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value> </value>
</item> </item>
<item>
<key> <string>editable</string> </key>
<value> <string></string> </value>
</item>
<item> <item>
<key> <string>enabled</string> </key> <key> <string>enabled</string> </key>
<value> <value>
...@@ -107,7 +103,7 @@ ...@@ -107,7 +103,7 @@
</item> </item>
<item> <item>
<key> <string>editable</string> </key> <key> <string>editable</string> </key>
<value> <int>1</int> </value> <value> <int>0</int> </value>
</item> </item>
<item> <item>
<key> <string>enabled</string> </key> <key> <string>enabled</string> </key>
......
...@@ -63,10 +63,28 @@ ...@@ -63,10 +63,28 @@
<key> <string>form_id</string> </key> <key> <string>form_id</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
</item> </item>
<item>
<key> <string>items</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>size</string> </key>
<value> <string></string> </value>
</item>
<item> <item>
<key> <string>target</string> </key> <key> <string>target</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
</item> </item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>view_separator</string> </key>
<value> <string></string> </value>
</item>
</dictionary> </dictionary>
</value> </value>
</item> </item>
...@@ -85,24 +103,7 @@ ...@@ -85,24 +103,7 @@
<item> <item>
<key> <string>items</string> </key> <key> <string>items</string> </key>
<value> <value>
<list> <list/>
<tuple>
<string>Manager</string>
<string>Manager</string>
</tuple>
<tuple>
<string>Author</string>
<string>Author</string>
</tuple>
<tuple>
<string>Assignor</string>
<string>Assignor</string>
</tuple>
<tuple>
<string>Assignee</string>
<string>Assignee</string>
</tuple>
</list>
</value> </value>
</item> </item>
<item> <item>
...@@ -131,4 +132,17 @@ ...@@ -131,4 +132,17 @@
</dictionary> </dictionary>
</pickle> </pickle>
</record> </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: [(role, role) for role in context.valid_roles()]</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData> </ZopeData>
...@@ -6,12 +6,12 @@ new_group_list = new_line.split('"') ...@@ -6,12 +6,12 @@ new_group_list = new_line.split('"')
if len(new_group_list) != 5: if len(new_group_list) != 5:
return False return False
before, portal_type, module, erp5_portal_type, after = new_group_list before, _, module, erp5_portal_type, after = new_group_list
if before != '<global name=' or module != ' module=' or erp5_portal_type != 'erp5.portal_type' or after != '/>': if before != '<global name=' or module != ' module=' or erp5_portal_type != 'erp5.portal_type' or after != '/>':
return False return False
old_group_list = old_line_list[0].split('"') old_group_list = old_line_list[0].split('"')
if len(old_group_list) == 5: if len(old_group_list) == 5:
before2, ignore, module2, products_erp5type, after2 = old_group_list before2, _, module2, products_erp5type, after2 = old_group_list
return before2 == before and module2 == module and products_erp5type.startswith("Products.ERP5Type.Document.") and after2 == after return before2 == before and module2 == module and products_erp5type.startswith("Products.ERP5Type.Document.") and after2 == after
return False return False
...@@ -85,8 +85,8 @@ ...@@ -85,8 +85,8 @@
<list> <list>
<string>my_parameter_signature</string> <string>my_parameter_signature</string>
<string>my_description</string> <string>my_description</string>
<string>error_message</string> <string>your_error_message</string>
<string>warning_message</string> <string>your_warning_message</string>
</list> </list>
</value> </value>
</item> </item>
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>error_message</string> </value> <value> <string>your_error_message</string> </value>
</item> </item>
<item> <item>
<key> <string>message_values</string> </key> <key> <string>message_values</string> </key>
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>warning_message</string> </value> <value> <string>your_warning_message</string> </value>
</item> </item>
<item> <item>
<key> <string>message_values</string> </key> <key> <string>message_values</string> </key>
......
...@@ -107,10 +107,6 @@ ...@@ -107,10 +107,6 @@
<key> <string>columns</string> </key> <key> <string>columns</string> </key>
<value> <value>
<list> <list>
<tuple>
<string>id</string>
<string>ID</string>
</tuple>
<tuple> <tuple>
<string>reference</string> <string>reference</string>
<string>Reference</string> <string>Reference</string>
...@@ -119,10 +115,6 @@ ...@@ -119,10 +115,6 @@
<string>title</string> <string>title</string>
<string>Title</string> <string>Title</string>
</tuple> </tuple>
<tuple>
<string>callable_type</string>
<string>Callable Type</string>
</tuple>
<tuple> <tuple>
<string>parameter_signature</string> <string>parameter_signature</string>
<string>Parameters</string> <string>Parameters</string>
...@@ -186,10 +178,6 @@ ...@@ -186,10 +178,6 @@
<key> <string>url_columns</string> </key> <key> <string>url_columns</string> </key>
<value> <value>
<list> <list>
<tuple>
<string>id</string>
<string>WorkflowScript_getListBoxURL</string>
</tuple>
<tuple> <tuple>
<string>reference</string> <string>reference</string>
<string>WorkflowScript_getListBoxURL</string> <string>WorkflowScript_getListBoxURL</string>
...@@ -198,10 +186,6 @@ ...@@ -198,10 +186,6 @@
<string>title</string> <string>title</string>
<string>WorkflowScript_getListBoxURL</string> <string>WorkflowScript_getListBoxURL</string>
</tuple> </tuple>
<tuple>
<string>callable_type</string>
<string>WorkflowScript_getListBoxURL</string>
</tuple>
<tuple> <tuple>
<string>parameter_signature</string> <string>parameter_signature</string>
<string>WorkflowScript_getListBoxURL</string> <string>WorkflowScript_getListBoxURL</string>
......
...@@ -58,7 +58,7 @@ def manage_page_footer(self): ...@@ -58,7 +58,7 @@ def manage_page_footer(self):
else: else:
mode = 'html' mode = 'html'
textarea_selector = 'textarea[name="filedata:text"]' textarea_selector = 'textarea[name="filedata:text"]'
elif document.meta_type in ('Script (Python)', ): elif document.meta_type in ('Script (Python)', 'ERP5 Python Script', 'ERP5 Workflow Script', ):
mode = 'python' mode = 'python'
textarea_selector = 'textarea[name="body:text"]' textarea_selector = 'textarea[name="body:text"]'
# printed is from RestrictedPython.RestrictionMutator the rest comes # printed is from RestrictedPython.RestrictionMutator the rest comes
...@@ -81,6 +81,10 @@ def manage_page_footer(self): ...@@ -81,6 +81,10 @@ def manage_page_footer(self):
mode = 'xml' mode = 'xml'
textarea_selector = 'textarea[name="text:text"]' textarea_selector = 'textarea[name="text:text"]'
if mode == 'plain_text':
if document.getId().endswith('.less'):
mode = 'less'
if not textarea_selector: if not textarea_selector:
return default return default
......
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