Commit 700cf6b3 authored by Ayush Tiwari's avatar Ayush Tiwari

[erp_hal_json_style]: count_method should not fail if it is empty or invalid

parent 9501244b
...@@ -1862,16 +1862,29 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -1862,16 +1862,29 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
if source_field is not None and source_field_meta_type == "ListBox": if source_field is not None and source_field_meta_type == "ListBox":
# Trigger count method if exist # Trigger count method if exist
# XXX No need to count if no pagination # XXX No need to count if no pagination
count_method = source_field.get_value('count_method') count_method = source_field.get_value('count_method') or None
if count_method != "" and count_method.getMethodName() != list_method: count_method_name = count_method.getMethodName() if count_method is not None else ""
# Only try to get count method results in case method name exists, in all
# other cases, just pass.
if count_method_name != "" and count_method_name != list_method:
count_kw = dict(catalog_kw) count_kw = dict(catalog_kw)
# Drop not needed parameters # Drop not needed parameters
count_kw.pop('selection', None) count_kw.pop('selection', None)
count_kw.pop('selection_name', None) count_kw.pop('selection_name', None)
count_kw.pop("sort_on", None) count_kw.pop("sort_on", None)
count_kw.pop("limit", None) count_kw.pop("limit", None)
count_method_result = getattr(traversed_document, count_method.getMethodName())(REQUEST=REQUEST, **count_kw) try:
result_dict['_embedded']['count'] = ensureSerializable(count_method_result[0][0]) count_method = getattr(traversed_document, count_method_name)
count_method_result = count_method(REQUEST=REQUEST, **count_kw)
result_dict['_embedded']['count'] = ensureSerializable(count_method_result[0][0])
except (Unauthorized, AttributeError, ValueError) as error:
# In case there is no count_method or some invalid mehtod, instead of
# raising error and breaking the view, its better to log on as warning
# and just pass. This also ensures we have compatibilty with how old
# UI behave in these cases.
log(str(error))
pass
contents_stat_list = [] contents_stat_list = []
# in case the search was issued by listbox we can provide results of # in case the search was issued by listbox we can provide results of
......
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