Commit cde69e3d authored by Romain Courteaud's avatar Romain Courteaud

[erp5_hal_json_style] No need to fetch getListItemUrlDict for every columns

parent c2c28029
...@@ -1778,6 +1778,8 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -1778,6 +1778,8 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
'value': brain_uid 'value': brain_uid
} }
is_getListItemUrlDict_calculated = False
for select in select_list: for select in select_list:
contents_item[select] = {} contents_item[select] = {}
editable_field = editable_field_dict.get(select, None) editable_field = editable_field_dict.get(select, None)
...@@ -1821,6 +1823,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -1821,6 +1823,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
if select in url_column_dict: if select in url_column_dict:
# Check if we get URL parameters using listbox field `url_columns` # Check if we get URL parameters using listbox field `url_columns`
try: try:
# XXX call on aq_base?
url_column_method = getattr(brain, url_column_dict[select]) url_column_method = getattr(brain, url_column_dict[select])
# Result of `url_column_method` must be a dictionary in the format # Result of `url_column_method` must be a dictionary in the format
# {'command': <command_name, ex: 'raw', 'push_history'>, # {'command': <command_name, ex: 'raw', 'push_history'>,
...@@ -1838,10 +1841,15 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -1838,10 +1841,15 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
if url_column_dict[select]: if url_column_dict[select]:
log("Invalid URL method {!s} on column {}".format(url_column_dict[select], select), level=800) log("Invalid URL method {!s} on column {}".format(url_column_dict[select], select), level=800)
elif getattr(brain, 'getListItemUrlDict', None) is not None: else:
if not is_getListItemUrlDict_calculated:
# XXX If only available on brains, maybe better to call on aq_self
getBrainListItemUrlDict = getattr(brain, 'getListItemUrlDict', None)
is_getListItemUrlDict_calculated = True
if getBrainListItemUrlDict is not None:
# Check if we can get URL result from the brain # Check if we can get URL result from the brain
try: try:
url_parameter_dict = brain.getListItemUrlDict( url_parameter_dict = getBrainListItemUrlDict(
select, result_index, catalog_kw['selection_name'] select, result_index, catalog_kw['selection_name']
) )
except (ConflictError, RuntimeError): except (ConflictError, RuntimeError):
......
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