From 854e8e3e2f7199c46639184dcffdc0ee2d87f04d Mon Sep 17 00:00:00 2001 From: Xiaowu Zhang <xiaowu.zhang@tiolive.com> Date: Fri, 19 Feb 2016 18:18:09 +0000 Subject: [PATCH] erp5_hal_json_style: listbox support field alias rules --- .../ERP5Document_getHateoas.xml | 13 +- .../test.erp5.testHalJsonStyle.py | 13 +- .../testFieldAliasRules.xml | 149 ++++++++++++++++++ 3 files changed, 171 insertions(+), 4 deletions(-) create mode 100644 bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_listbox_zuite/testFieldAliasRules.xml diff --git a/bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.xml b/bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.xml index 272d535048..9c55ef27ac 100644 --- a/bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.xml +++ b/bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.xml @@ -83,6 +83,12 @@ def byteify(string):\n \n def getProtectedProperty(document, select):\n try:\n + #see https://lab.nexedi.com/nexedi/erp5/blob/master/product/ERP5Form/ListBox.py#L2293\n + try:\n + select = select[select.rindex(\'.\') + 1:]\n + except ValueError:\n + pass\n +\n return document.getProperty(select, d=None)\n except (ConflictError, RuntimeError):\n raise\n @@ -1025,9 +1031,10 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, # XXX Proxy field are not correctly handled in traversed_document of web site\n listbox_form = getattr(traversed_document, listbox_field.aq_parent.id)\n for select in select_list:\n - # See Listbox.py getEditableField method\n - if listbox_form.has_field("%s_%s" % (listbox_field_id, select), include_disabled=1):\n - editable_field_dict[select] = listbox_form.get_field("%s_%s" % (listbox_field_id, select), include_disabled=1)\n + # See Listbox.py getValueList --> getEditableField & getColumnAliasList method\n + tmp = select.replace(\'.\', \'_\')\n + if listbox_form.has_field("%s_%s" % (listbox_field_id, tmp), include_disabled=1):\n + editable_field_dict[select] = listbox_form.get_field("%s_%s" % (listbox_field_id, tmp), include_disabled=1)\n \n for sql_document in sql_list:\n try:\n diff --git a/bt5/erp5_hal_json_style/TestTemplateItem/portal_components/test.erp5.testHalJsonStyle.py b/bt5/erp5_hal_json_style/TestTemplateItem/portal_components/test.erp5.testHalJsonStyle.py index bce1649f1e..de36a991a9 100644 --- a/bt5/erp5_hal_json_style/TestTemplateItem/portal_components/test.erp5.testHalJsonStyle.py +++ b/bt5/erp5_hal_json_style/TestTemplateItem/portal_components/test.erp5.testHalJsonStyle.py @@ -471,6 +471,17 @@ class TestERP5Document_getHateoas_mode_traverse(ERP5HALJSONStyleSkinsMixin): @changeSkin('Hal') def test_getHateoasDocument_default_view(self): document = self._makeDocument() + document.Foo_view.listbox.ListBox_setPropertyList( + field_title = 'Foo Lines', + field_list_method = 'objectValues', + field_portal_types = 'Foo Line | Foo Line', + field_stat_method = 'portal_catalog', + field_stat_columns = 'quantity | Foo_statQuantity', + field_editable = 1, + field_columns = 'id|ID\ntitle|Title\nquantity|Quantity\nstart_date|Date\ncatalog.uid|Uid', + field_editable_columns = 'id|ID\ntitle|Title\nquantity|quantity\nstart_date|Date', + field_search_columns = 'id|ID\ntitle|Title\nquantity|Quantity\nstart_date|Date',) + parent = document.getParentValue() fake_request = do_fake_request("GET") result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(REQUEST=fake_request, mode="traverse", relative_url=document.getRelativeUrl(), view="view") @@ -551,7 +562,7 @@ class TestERP5Document_getHateoas_mode_traverse(ERP5HALJSONStyleSkinsMixin): self.assertEqual(result_dict['_embedded']['_view']['listbox']['list_method'], 'objectValues') self.assertEqual(result_dict['_embedded']['_view']['listbox']['query'], 'urn:jio:allDocs?query=') self.assertEqual(result_dict['_embedded']['_view']['listbox']['portal_type'], [['Foo Line', 'Foo Line']]) - self.assertEqual(result_dict['_embedded']['_view']['listbox']['column_list'], [['id', 'ID'], ['title', 'Title'], ['quantity', 'Quantity'], ['start_date', 'Date']]) + self.assertEqual(result_dict['_embedded']['_view']['listbox']['column_list'], [['id', 'ID'], ['title', 'Title'], ['quantity', 'Quantity'], ['start_date', 'Date'], ['catalog.uid', 'Uid']]) self.assertEqual(result_dict['_embedded']['_view']['listbox']['search_column_list'], [['id', 'ID'], ['title', 'Title'], ['quantity', 'Quantity'], ['start_date', 'Date']]) self.assertEqual(result_dict['_embedded']['_view']['listbox']['editable_column_list'], [['id', 'ID'], ['title', 'Title'], ['quantity', 'quantity'], ['start_date', 'Date']]) self.assertEqual(result_dict['_embedded']['_view']['listbox']['sort_column_list'], [['id', 'ID'], ['title', 'Title'], ['quantity', 'Quantity'], ['start_date', 'Date']]) diff --git a/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_listbox_zuite/testFieldAliasRules.xml b/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_listbox_zuite/testFieldAliasRules.xml new file mode 100644 index 0000000000..976538d1c8 --- /dev/null +++ b/bt5/erp5_web_renderjs_ui_test/PathTemplateItem/portal_tests/renderjs_ui_listbox_zuite/testFieldAliasRules.xml @@ -0,0 +1,149 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/> + </pickle> + <pickle> + <dictionary> + <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_subpath</string> </key> + <value> <string>traverse_subpath</string> </value> + </item> + </dictionary> + </value> + </item> + </dictionary> + </state> + </object> + </value> + </item> + <item> + <key> <string>_text</string> </key> + <value> <unicode encoding="cdata"><![CDATA[ + +<html xmlns:tal="http://xml.zope.org/namespaces/tal"\n + xmlns:metal="http://xml.zope.org/namespaces/metal">\n +<head>\n +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\n +<title>Test RenderJS UI</title>\n +</head>\n +<body>\n +<table cellpadding="1" cellspacing="1" border="1">\n +<thead>\n +<tr><td rowspan="1" colspan="3">Test RenderJS UI</td></tr>\n +</thead><tbody>\n +<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/init" />\n +\n +<!-- Clean Up -->\n +<tr>\n + <td>open</td>\n + <td>${base_url}/bar_module/ListBoxZuite_reset</td>\n + <td></td>\n +</tr>\n +\n +<tr>\n + <td>assertTextPresent</td>\n + <td>Reset Successfully.</td>\n + <td></td>\n +</tr>\n +\n +<tr>\n + <td>open</td>\n + <td>${base_url}/foo_module/FooModule_createObjects</td>\n + <td></td>\n +</tr>\n +<tr>\n + <td>assertTextPresent</td>\n + <td>Created Successfully.</td>\n + <td></td>\n +</tr>\n +\n +\n +<tr>\n + <td>open</td>\n + <td>${base_url}/foo_module/FooModule_viewFooList/listbox/ListBox_setPropertyList?field_columns=id%7CID%0Atitle%7CTitle%0Adelivery.quantity%7CQuantity</td>\n + <td></td>\n +</tr>\n +\n +<tr>\n + <td>assertTextPresent</td>\n + <td>Set Successfully.</td>\n + <td></td>\n +</tr>\n +\n +<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/wait_for_activities" />\n +\n +\n +<!-- Initialize -->\n +<tr>\n + <td>open</td>\n + <td>${base_url}/web_site_module/renderjs_runner/#/foo_module</td>\n + <td></td>\n +</tr>\n +\n +<tr>\n + <td>waitForElementPresent</td>\n + <td>//a[@data-i18n=\'Previous\']</td>\n + <td></td>\n +</tr>\n +\n +<!-- check quanlity is display correctly -->\n +<tr>\n + <td>waitForElementPresent</td>\n + <td>//a[@class=\'ui-link\' and text() =\'1\']</td>\n + <td></td>\n +</tr>\n +\n +\n +<tr>\n + <td>verifyElementPresent</td>\n + <td>//a[@class=\'ui-link\' and text() =\'1\']</td>\n + <td></td>\n +</tr>\n +\n +\n +</tbody></table>\n +</body>\n +</html> + +]]></unicode> </value> + </item> + <item> + <key> <string>content_type</string> </key> + <value> <string>text/html</string> </value> + </item> + <item> + <key> <string>expand</string> </key> + <value> <int>0</int> </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>testFieldAliasRules</string> </value> + </item> + <item> + <key> <string>output_encoding</string> </key> + <value> <string>utf-8</string> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <unicode></unicode> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> -- 2.30.9