Commit f87704ac authored by Xiaowu Zhang's avatar Xiaowu Zhang Committed by Ayush Tiwari

erp5_hal_json_style: pass parameter for rendering form

for listbox, query use full_text to search, parameter is used for list method
parent 09c476f8
......@@ -24,5 +24,6 @@ return context.ERP5Document_getHateoas(
sort_on=sort_on,
local_roles=local_roles,
selection_domain=selection_domain,
parameter=parameter,
restricted=1
)
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, local_roles=None, form=None, relative_url=None, list_method=None, default_param_json=None, form_relative_url=None, bulk_list="[]", sort_on=None, selection_domain=None</string> </value>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, local_roles=None, form=None, relative_url=None, list_method=None, default_param_json=None, form_relative_url=None, bulk_list="[]", sort_on=None, selection_domain=None, parameter=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -413,6 +413,8 @@ url_template_dict = {
"&relative_url=%(relative_url)s&view=%(view)s",
"traverse_generator_non_view": "%(root_url)s/%(script_id)s?mode=traverse" + \
"&relative_url=%(relative_url)s&view=%(view)s&form_id=%(form_id)s",
"traverse_generator_with_parameter": "%(root_url)s/%(script_id)s?mode=traverse" + \
"&relative_url=%(relative_url)s&view=%(view)s&parameter=%(parameter)s",
"traverse_template": "%(root_url)s/%(script_id)s?mode=traverse" + \
"{&relative_url,view}",
"search_template": "%(root_url)s/%(script_id)s?mode=search" + \
......@@ -471,11 +473,10 @@ def getFieldDefault(form, field, key, value=None):
return value
def renderField(traversed_document, field, form, value=None, meta_type=None, key=None, key_prefix=None, selection_params=None):
def renderField(traversed_document, field, form, value=None, meta_type=None, key=None, key_prefix=None, selection_params=None, parameter=None):
"""Extract important field's attributes into `result` dictionary."""
if selection_params is None:
selection_params = {}
# some TALES expressions are using Base_getRelatedObjectParameter which requires that
previous_request_field = REQUEST.other.pop('field_id', None)
REQUEST.other['field_id'] = field.id
......@@ -742,6 +743,10 @@ def renderField(traversed_document, field, form, value=None, meta_type=None, key
# listbox's default parameters
default_params.update(selection_params)
if parameter is not None:
default_params.update(ensureDeserialized(byteify(
json.loads(urlsafe_b64decode(parameter)))))
# ListBoxes in report view has portal_type defined already in default_params
# in that case we prefer non_empty version
list_method_query_dict = default_params.copy()
......@@ -905,7 +910,7 @@ def renderField(traversed_document, field, form, value=None, meta_type=None, key
return result
def renderForm(traversed_document, form, response_dict, key_prefix=None, selection_params=None):
def renderForm(traversed_document, form, response_dict, key_prefix=None, selection_params=None, parameter=None):
"""
Render a `form` in plain python dict.
......@@ -988,7 +993,7 @@ def renderForm(traversed_document, form, response_dict, key_prefix=None, selecti
if not field.get_value("enabled"):
continue
try:
response_dict[field.id] = renderField(traversed_document, field, form, key_prefix=key_prefix, selection_params=selection_params)
response_dict[field.id] = renderField(traversed_document, field, form, key_prefix=key_prefix, selection_params=selection_params, parameter=parameter)
if field_errors.has_key(field.id):
response_dict[field.id]["error_text"] = field_errors[field.id].error_text
except AttributeError:
......@@ -1363,8 +1368,8 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
return traversed_document.Base_redirect(keep_items={
'portal_status_message': status_message})
renderForm(traversed_document, renderer_form, embedded_dict)
renderForm(traversed_document, renderer_form, embedded_dict, parameter=parameter)
result_dict['_embedded'] = {
'_view': embedded_dict
}
......@@ -1803,12 +1808,23 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
contents_item[select]['jio_key'] = traversed_document.getRelativeUrl()
if generate_view:
if 'parameter' in contents_item[select]:
contents_item[select]['view'] = url_template_dict["traverse_generator_with_parameter"] % {
"root_url": site_root.absolute_url(),
"script_id": script.id,
"relative_url": contents_item[select]['jio_key'].replace("/", "%2F"),
"view": url_parameter_dict[select]['view'],
"parameter": urlsafe_b64encode(
json.dumps(ensureSerializable(contents_item[select]['parameter'])))
}
else:
contents_item[select]['view'] = url_template_dict["traverse_generator"] % {
"root_url": site_root.absolute_url(),
"script_id": script.id,
"relative_url": contents_item[select]['jio_key'].replace("/", "%2F"),
"view": url_parameter_dict[select]['view']
}
# endfor select
REQUEST.other.pop('cell', None)
contents_list.append(contents_item)
......
......@@ -56,7 +56,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, local_roles=None, form=None, relative_url=None, restricted=0, list_method=None, default_param_json=None, form_relative_url=None, bulk_list="[]", sort_on=None, selection_domain=None</string> </value>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, local_roles=None, form=None, relative_url=None, restricted=0, list_method=None, default_param_json=None, form_relative_url=None, bulk_list="[]", sort_on=None, selection_domain=None, parameter=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
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