Commit f1b1f6a8 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_hal_json_style] Use usual rendering for relation field listbox

As for xhtml_style, always use Base_viewRelatedObjectList by correctly filling the REQUEST, and let it render as any other form.
parent bf57228a
......@@ -730,13 +730,10 @@ def renderField(traversed_document, field, form, value=None, meta_type=None, key
listbox_ids = [('Base_viewRelatedObjectListBase/listbox','default')]
listbox = {}
rel_form = getattr(traversed_document, 'Base_viewRelatedObjectList')
listbox_form_field = rel_form.get_field('listbox')
for (listbox_path, listbox_name) in listbox_ids:
(listbox_form_name, listbox_field_name) = listbox_path.split('/', 2)
# do not override "global" `form`
rel_form = getattr(traversed_document, listbox_form_name)
# find listbox field
listbox_form_field = filter(lambda f: f.getId() == listbox_field_name, rel_form.get_fields())[0]
REQUEST.set('proxy_listbox_id', listbox_path)
# Set only relation_form_id but do NOT change form_id to the relation_form neither field_id to the listbox
# field_id must point to a relation field
REQUEST.set('relation_form_id', rel_form.id)
......@@ -745,30 +742,8 @@ def renderField(traversed_document, field, form, value=None, meta_type=None, key
# because Relation stuff expects the original RelationField to be the one "being rendered"
subfield = renderField(traversed_document, listbox_form_field, rel_form, request_field=False)
del REQUEST.other['relation_form_id']
del REQUEST.other['proxy_listbox_id']
# overwrite, like Base_getRelatedObjectParameter does
if subfield["portal_type"] == []:
subfield["portal_type"] = field.get_value('portal_type')
if relation_sort:
subfield["sort"] = relation_sort
listbox_query_kw = kw.copy()
listbox_query_kw.update(dict(portal_type = [x[-1] for x in subfield["portal_type"]],
**subfield["default_params"]))
subfield["query"] = url_template_dict["jio_search_template"] % {
"query": make_query({"query": sql_catalog.buildQuery(
listbox_query_kw, ignore_unknown_columns=True
).asSearchTextExpression(sql_catalog)})
}
# Kato: why?
if "list_method_template" in subfield:
del subfield["list_method_template"]
subfield["list_method"] = "portal_catalog"
subfield["title"] = Base_translateString(title)
#set default listbox's column list to relation's column list
if listbox_form_name == 'Base_viewRelatedObjectListBase' and len(column_list) > 0:
subfield["column_list"] = []
for tmp_column in column_list:
subfield["column_list"].append((tmp_column[0], Base_translateString(tmp_column[1])))
listbox[Base_translateString(listbox_name)] = subfield
result.update({
......@@ -885,6 +860,15 @@ def renderField(traversed_document, field, form, value=None, meta_type=None, key
if (True): # editable_column_list (we need that template fields resolution
# (issued by existence of `form_relative_url`) always kicks in
extra_param_dict = {
# in case of a dialog the form_id points to previous form, otherwise current form
"form_id": REQUEST.get('form_id', form.id)
}
# Proxy listbox id is an hardcoded parameter used in relation field listbox
# For now, keep it hardcoded, until another use case is found to provide
# a default extra_param_dict
if REQUEST.get('proxy_listbox_id', None) is not None:
extra_param_dict['proxy_listbox_id'] = REQUEST.get('proxy_listbox_id')
list_method_custom = url_template_dict["custom_search_template"] % {
"root_url": site_root.absolute_url(),
"script_id": script.id,
......@@ -893,9 +877,8 @@ def renderField(traversed_document, field, form, value=None, meta_type=None, key
"list_method": list_method_name,
"default_param_json": urlsafe_b64encode(
json.dumps(ensureSerializable(list_method_query_dict))),
# in case of a dialog the form_id points to previous form, otherwise current form
"extra_param_json": urlsafe_b64encode(
json.dumps(ensureSerializable({"form_id": REQUEST.get('form_id', form.id)})))
json.dumps(ensureSerializable(extra_param_dict)))
}
# once we imprint `default_params` into query string of 'list method' we
# don't want them to propagate to the query as well
......
<?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>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>testMultiRelationFieldSearchWithProxyListbox</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>
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test RenderJS UI</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Test RenderJS UI</td></tr>
</thead><tbody>
<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/init" />
<!-- Clean Up -->
<tr>
<td>open</td>
<td>${base_url}/foo_module/ListBoxZuite_reset</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Reset Successfully.</td>
<td></td>
</tr>
<!-- Initialize -->
<tr>
<td>open</td>
<td>${base_url}/web_site_module/renderjs_runner/#/foo_module</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//a[@data-i18n='Add']</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>link=Add</td>
<td></td>
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/submit_dialog" />
<tal:block tal:define="notification_configuration python: {'class': 'success',
'text': 'Document created.'}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_notification" />
</tal:block>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
<tr>
<td>waitForElementPresent</td>
<td>//a[@data-i18n="Views"]</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//a[@data-i18n="Views"]</td>
<td></td>
</tr>
<tr>
<td>storeLocation</td>
<td>url</td>
<td></td>
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/wait_for_activities" />
<tr>
<td>open</td>
<td>${url}</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//a[@data-i18n="Relation Fields"]</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//a[@data-i18n="Relation Fields"]</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//input[@name="field_my_bar_category_id_list"]</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//div[@data-gadget-scope="field_my_bar_category_id_list"]//button</td>
<td></td>
</tr>
<!-- Select the second template -->
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
<tr>
<td>waitForElementPresent</td>
<td>//div[contains(@data-gadget-url, 'gadget_erp5_page_relation_search.html')]//select</td>
<td></td>
</tr>
<tr>
<td>select</td>
<td>//div[contains(@data-gadget-url, 'gadget_erp5_page_relation_search.html')]//select</td>
<td>label=Foo Listbox</td>
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_listbox_loaded" />
<tal:block tal:define="header_configuration python: {'text': 'ID', 'index': 0}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/check_listbox_header" />
</tal:block>
<tal:block tal:define="header_configuration python: {'text': 'Title', 'index': 1}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/check_listbox_header" />
</tal:block>
<tal:block tal:define="header_configuration python: {'text': 'Quantity', 'index': 2}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/check_listbox_header" />
</tal:block>
<!-- a integer field is used to render the quantity on this listbox -->
<tr>
<td>verifyElementPresent</td>
<td>//div[@data-gadget-scope='field_listbox']//tbody/tr[1]//a//div[@class='floatfield']//p[contains(text(), '0')]</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
\ No newline at end of file
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