Commit 18e2f507 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_hal_json_style] Allow to disable listbox search/sort

parent e78e5a49
......@@ -609,14 +609,14 @@ def renderField(traversed_document, field, form, value=MARKER, meta_type=None, k
# try to get specified searchable columns and fail back to all searchable columns
search_column_list = [(name, _translate(title))
for name, title in field.get_value("search_columns")
if sql_catalog.isValidColumn(name)] or catalog_column_list
for name, title in (field.get_value("search_columns") or catalog_column_list)
if sql_catalog.isValidColumn(name)]
# try to get specified sortable columns and fail back to searchable fields
sort_column_list = [(name, _translate(title))
for name, title in (selection_params.get('selection_sort_order', [])
or field.get_value("sort_columns"))
if sql_catalog.isValidColumn(name)] or search_column_list
or field.get_value("sort_columns") or search_column_list)
if sql_catalog.isValidColumn(name)]
# portal_type list can be overriden by selection too
# since it can be intentionally empty we don't override with non-empty field value
portal_type_list = selection_params.get("portal_type", field.get_value('portal_types'))
......
......@@ -666,6 +666,84 @@ class TestERP5Document_getHateoas_mode_traverse(ERP5HALJSONStyleSkinsMixin):
document.getRelativeUrl()))
self.assertEqual(result_dict['_embedded']['_view']['_actions']['put']['method'], 'POST')
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasDocument_disable_listbox_search_column(self):
document = self._makeDocument()
# Disabling search also disable sort if not configured
document.Foo_view.listbox.ListBox_setPropertyList(
field_title = 'Foo Lines',
field_list_method = 'objectValues',
field_portal_types = 'Foo Line | Foo Line',
field_columns = 'id|ID\ntitle|Title\nquantity|Quantity\nstart_date|Date\ncatalog.uid|Uid',
field_search_columns = 'foo|Foo')
fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(REQUEST=fake_request, mode="traverse", relative_url=document.getRelativeUrl(), view="view")
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/hal+json"
)
result_dict = json.loads(result)
self.assertEqual(result_dict['_embedded']['_view']['listbox']['column_list'], [['id', 'ID'], ['title', 'Title'], ['quantity', 'Quantity'], ['start_date', 'Date'], ['catalog.uid', 'Uid']])
self.assertEqual(result_dict['_embedded']['_view']['listbox']['search_column_list'], [])
self.assertEqual(result_dict['_embedded']['_view']['listbox']['editable_column_list'], [['id', 'id']])
self.assertEqual(result_dict['_embedded']['_view']['listbox']['sort_column_list'], [])
# Disabling search does not impact configured sort
document.Foo_view.listbox.ListBox_setPropertyList(
field_title = 'Foo Lines',
field_list_method = 'objectValues',
field_portal_types = 'Foo Line | Foo Line',
field_columns = 'id|ID\ntitle|Title\nquantity|Quantity\nstart_date|Date\ncatalog.uid|Uid',
field_search_columns = 'foo|Foo',
field_sort_columns = 'title|Title')
fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(REQUEST=fake_request, mode="traverse", relative_url=document.getRelativeUrl(), view="view")
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/hal+json"
)
result_dict = json.loads(result)
self.assertEqual(result_dict['_embedded']['_view']['listbox']['column_list'], [['id', 'ID'], ['title', 'Title'], ['quantity', 'Quantity'], ['start_date', 'Date'], ['catalog.uid', 'Uid']])
self.assertEqual(result_dict['_embedded']['_view']['listbox']['search_column_list'], [])
self.assertEqual(result_dict['_embedded']['_view']['listbox']['editable_column_list'], [['id', 'id']])
self.assertEqual(result_dict['_embedded']['_view']['listbox']['sort_column_list'], [['title', 'Title']])
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasDocument_disable_listbox_sort_column(self):
document = self._makeDocument()
document.Foo_view.listbox.ListBox_setPropertyList(
field_title = 'Foo Lines',
field_list_method = 'objectValues',
field_portal_types = 'Foo Line | Foo Line',
field_columns = 'id|ID\ntitle|Title\nquantity|Quantity\nstart_date|Date\ncatalog.uid|Uid',
field_sort_columns = 'foo|Foo')
fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(REQUEST=fake_request, mode="traverse", relative_url=document.getRelativeUrl(), view="view")
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/hal+json"
)
result_dict = json.loads(result)
self.assertEqual(result_dict['_embedded']['_view']['listbox']['column_list'], [['id', 'ID'], ['title', 'Title'], ['quantity', 'Quantity'], ['start_date', 'Date'], ['catalog.uid', 'Uid']])
self.assertEqual(result_dict['_embedded']['_view']['listbox']['search_column_list'], [['id', 'ID'], ['title', 'Title'], ['quantity', 'Quantity'], ['start_date', 'Date'], ['catalog.uid', 'Uid']])
self.assertEqual(result_dict['_embedded']['_view']['listbox']['editable_column_list'], [['id', 'id']])
self.assertEqual(result_dict['_embedded']['_view']['listbox']['sort_column_list'], [])
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
......
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