Commit 325c5563 authored by Nicolas Wavrant's avatar Nicolas Wavrant

erp5_hal_json_style: do not limit infinite listboxes

If the max number of lines of a listbox was set to 0, meaning "no limit set", then ERP5Document_getHateoas would still return a paginated list of 10 results, 10 being
the default set in the parameters of ERP5Document_getHateoas.

It looks like there is a beginning of support for such case in ERP5Document_getHateoas,
with the appearance of code such as "if limit", but the bug comes from the lack of typing in the JS-jIO-JSON-ERP5's HAL interface. In case of a limit set to 0 in the listbox configuration, ERP5
would receive the string "0" which is a non empty string. It would fail the condition and would
be handled like there is a limit, or of 0 - so no result - or of a default limit chosen by the code.
parent 5d240501
......@@ -2007,14 +2007,20 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
editable_field_dict[select] = proxy_form.get_field(proxy_field_name, include_disabled=1)
break
# handle the case when list-scripts are ignoring `limit` - paginate for them
if limit is not None:
# handle the case when list-scripts are ignoring `limit` - paginate for them.
# Except when `limit` is explicitely set to 0, meaning no limit.
if limit:
if isinstance(limit, (tuple, list)):
start, num_items = map(int, limit)
elif isinstance(limit, int):
start, num_items = 0, limit
else:
start, num_items = 0, int(limit)
if isinstance(limit, int):
limit_int = limit
else:
limit_int = int(limit)
if limit_int == 0:
start, num_items = 0, len(search_result_iterable)
else:
start, num_items = 0, int(limit_int)
if not (is_rendering_listbox and not has_listbox_a_count_method):
# the limit was most likely taken into account thus we don't need to slice
start, num_items = 0, len(search_result_iterable)
......
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