Commit 75c34345 authored by Romain Courteaud's avatar Romain Courteaud Committed by Cédric Le Ninivin

[erp5_hal_json_style] Fix listbox pagination

The pagination was not working when using the limit parameter, and when
the total number of documents is equal to the pagination limit + 1.
parent 5f102780
...@@ -1720,7 +1720,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -1720,7 +1720,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
start, num_items = 0, limit start, num_items = 0, limit
else: else:
start, num_items = 0, int(limit) start, num_items = 0, int(limit)
if len(search_result_iterable) <= num_items: 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 # the limit was most likely taken into account thus we don't need to slice
start, num_items = 0, len(search_result_iterable) start, num_items = 0, len(search_result_iterable)
else: else:
......
...@@ -1758,7 +1758,7 @@ return context.getPortalObject().portal_catalog(portal_type='Foo', sort_on=[('id ...@@ -1758,7 +1758,7 @@ return context.getPortalObject().portal_catalog(portal_type='Foo', sort_on=[('id
@simulate('Test_countCatalog', '*args, **kwargs', """ @simulate('Test_countCatalog', '*args, **kwargs', """
return context.getPortalObject().portal_catalog(portal_type='Foo', sort_on=[('id', 'ASC')]) return context.getPortalObject().portal_catalog(portal_type='Foo', sort_on=[('id', 'ASC')])
""") """)
@createIndexedDocument(quantity=2) @createIndexedDocument(quantity=3)
@changeSkin('Hal') @changeSkin('Hal')
def test_getHateoas_count_method(self, document_list): def test_getHateoas_count_method(self, document_list):
"""Test that count method also uses the query parameters. """Test that count method also uses the query parameters.
...@@ -1774,8 +1774,8 @@ return context.getPortalObject().portal_catalog(portal_type='Foo', sort_on=[('id ...@@ -1774,8 +1774,8 @@ return context.getPortalObject().portal_catalog(portal_type='Foo', sort_on=[('id
form_relative_url='portal_skins/erp5_ui_test/FooModule_viewFooList/listbox' form_relative_url='portal_skins/erp5_ui_test/FooModule_viewFooList/listbox'
) )
result_dict = json.loads(result) result_dict = json.loads(result)
self.assertEqual(len(result_dict['_embedded']['contents']), 2) self.assertEqual(len(result_dict['_embedded']['contents']), 3)
self.assertEqual(result_dict['_embedded']['count'], 2) self.assertEqual(result_dict['_embedded']['count'], 3)
# Check that limiting the number of result doesn't impact count # Check that limiting the number of result doesn't impact count
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
...@@ -1791,7 +1791,22 @@ return context.getPortalObject().portal_catalog(portal_type='Foo', sort_on=[('id ...@@ -1791,7 +1791,22 @@ return context.getPortalObject().portal_catalog(portal_type='Foo', sort_on=[('id
result_dict = json.loads(result) result_dict = json.loads(result)
# There is a count method on this listbox # There is a count method on this listbox
self.assertEqual(len(result_dict['_embedded']['contents']), 1) self.assertEqual(len(result_dict['_embedded']['contents']), 1)
self.assertEqual(result_dict['_embedded']['count'], 2) self.assertEqual(result_dict['_embedded']['count'], 3)
fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(
REQUEST=fake_request,
mode="search",
relative_url='foo_module',
list_method="searchFolder",
query='portal_type:"Foo"',
limit=[2, 3],
form_relative_url='portal_skins/erp5_ui_test/FooModule_viewFooList/listbox'
)
result_dict = json.loads(result)
# There is a count method on this listbox
self.assertEqual(len(result_dict['_embedded']['contents']), 1)
self.assertEqual(result_dict['_embedded']['count'], 3)
# Check that query parameters are passed to the count method # Check that query parameters are passed to the count method
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
...@@ -1810,7 +1825,7 @@ return context.getPortalObject().portal_catalog(portal_type='Foo', sort_on=[('id ...@@ -1810,7 +1825,7 @@ return context.getPortalObject().portal_catalog(portal_type='Foo', sort_on=[('id
@simulate('Base_getRequestUrl', '*args, **kwargs', 'return "http://example.org/bar"') @simulate('Base_getRequestUrl', '*args, **kwargs', 'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs', 'return "application/hal+json"') @simulate('Base_getRequestHeader', '*args, **kwargs', 'return "application/hal+json"')
@createIndexedDocument(quantity=2) @createIndexedDocument(quantity=3)
@changeSkin('Hal') @changeSkin('Hal')
def test_getHateoas_length_as_count_method(self, document_list): def test_getHateoas_length_as_count_method(self, document_list):
"""Test that erp5 listbox manually count result length. """Test that erp5 listbox manually count result length.
...@@ -1829,8 +1844,8 @@ return context.getPortalObject().portal_catalog(portal_type='Foo', sort_on=[('id ...@@ -1829,8 +1844,8 @@ return context.getPortalObject().portal_catalog(portal_type='Foo', sort_on=[('id
form_relative_url='portal_skins/erp5_ui_test/FooModule_viewFooList/listbox' form_relative_url='portal_skins/erp5_ui_test/FooModule_viewFooList/listbox'
) )
result_dict = json.loads(result) result_dict = json.loads(result)
self.assertEqual(len(result_dict['_embedded']['contents']), 2) self.assertEqual(len(result_dict['_embedded']['contents']), 3)
self.assertEqual(result_dict['_embedded']['count'], 2) self.assertEqual(result_dict['_embedded']['count'], 3)
# Check that limiting the number of result doesn't impact count # Check that limiting the number of result doesn't impact count
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
...@@ -1846,7 +1861,22 @@ return context.getPortalObject().portal_catalog(portal_type='Foo', sort_on=[('id ...@@ -1846,7 +1861,22 @@ return context.getPortalObject().portal_catalog(portal_type='Foo', sort_on=[('id
result_dict = json.loads(result) result_dict = json.loads(result)
# There is a count method on this listbox # There is a count method on this listbox
self.assertEqual(len(result_dict['_embedded']['contents']), 1) self.assertEqual(len(result_dict['_embedded']['contents']), 1)
self.assertEqual(result_dict['_embedded']['count'], 2) self.assertEqual(result_dict['_embedded']['count'], 3)
fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(
REQUEST=fake_request,
mode="search",
relative_url='foo_module',
list_method="searchFolder",
query='portal_type:"Foo"',
limit=[2, 3],
form_relative_url='portal_skins/erp5_ui_test/FooModule_viewFooList/listbox'
)
result_dict = json.loads(result)
# There is a count method on this listbox
self.assertEqual(len(result_dict['_embedded']['contents']), 1)
self.assertEqual(result_dict['_embedded']['count'], 3)
# Check that query parameters are passed to the count method # Check that query parameters are passed to the count method
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
......
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