Commit 066bf86c authored by Jérome Perrin's avatar Jérome Perrin

ERP5JS: Support None in listbox URL columns

See merge request !1150
parents 316caef6 711c04bb
...@@ -2015,25 +2015,25 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -2015,25 +2015,25 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
url_parameter_dict = None url_parameter_dict = 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: url_parameter_dict = {}
# XXX call on aq_base? url_column_method_id = url_column_dict[select]
url_column_method = getattr(brain, url_column_dict[select]) if url_column_method_id:
# Result of `url_column_method` must be a dictionary in the format try:
# {'command': <command_name, ex: 'raw', 'push_history'>, url_column_method = getattr(brain, url_column_method_id)
# 'options': {'url': <Absolute URL>, 'jio_key': <Relative URL of object>, 'view': <id of the view>}} except AttributeError:
url_parameter_dict = url_column_method(url_dict=True, # In case the URL method is invalid or empty, we expect to have no link
brain=brain, # for the column to maintain compatibility with old UI, hence we create
selection=catalog_kw['selection'], # an empty url_parameter_dict for these cases.
selection_name=catalog_kw['selection_name'],
column_id=select)
except AttributeError:
# In case the URL method is invalid or empty, we expect to have no link
# for the column to maintain compatibility with old UI, hence we create
# an empty url_parameter_dict for these cases.
url_parameter_dict = {}
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)
else:
# Result of `url_column_method` must be a dictionary in the format
# {'command': <command_name, ex: 'raw', 'push_history'>,
# 'options': {'url': <Absolute URL>, 'jio_key': <Relative URL of object>, 'view': <id of the view>}}
url_parameter_dict = url_column_method(url_dict=True,
brain=brain,
selection=catalog_kw['selection'],
selection_name=catalog_kw['selection_name'],
column_id=select)
else: else:
if not is_getListItemUrlDict_calculated: if not is_getListItemUrlDict_calculated:
# XXX If only available on brains, maybe better to call on aq_self # XXX If only available on brains, maybe better to call on aq_self
......
...@@ -1679,7 +1679,6 @@ return '%s/Base_viewMetadata?reset:int=1' % context.getRelativeUrl() ...@@ -1679,7 +1679,6 @@ return '%s/Base_viewMetadata?reset:int=1' % context.getRelativeUrl()
@changeSkin('Hal') @changeSkin('Hal')
def test_getHateoasDocument_listbox_check_url_column_different_view(self): def test_getHateoasDocument_listbox_check_url_column_different_view(self):
self._makeDocument() self._makeDocument()
# pass custom list method which expect input arguments
self.portal.foo_module.FooModule_viewFooList.listbox.ListBox_setPropertyList( self.portal.foo_module.FooModule_viewFooList.listbox.ListBox_setPropertyList(
field_url_columns = ['modification_date | Base_getUrl',]) field_url_columns = ['modification_date | Base_getUrl',])
...@@ -1729,7 +1728,6 @@ return url ...@@ -1729,7 +1728,6 @@ return url
""") """)
@changeSkin('Hal') @changeSkin('Hal')
def test_getHateoasDocument_listbox_check_url_column_absolute_url_with_field_rendering(self): def test_getHateoasDocument_listbox_check_url_column_absolute_url_with_field_rendering(self):
# pass custom list method which expect input arguments
self.portal.foo_module.FooModule_viewFooList.listbox.ListBox_setPropertyList( self.portal.foo_module.FooModule_viewFooList.listbox.ListBox_setPropertyList(
field_url_columns = ['modification_date | Base_getUrl',]) field_url_columns = ['modification_date | Base_getUrl',])
...@@ -1774,7 +1772,6 @@ return url ...@@ -1774,7 +1772,6 @@ return url
@changeSkin('Hal') @changeSkin('Hal')
def test_getHateoasDocument_listbox_check_url_column_absolute_url_without_field_rendering(self): def test_getHateoasDocument_listbox_check_url_column_absolute_url_without_field_rendering(self):
self._makeDocument() self._makeDocument()
# pass custom list method which expect input arguments
self.portal.foo_module.FooModule_viewFooList.listbox.ListBox_setPropertyList( self.portal.foo_module.FooModule_viewFooList.listbox.ListBox_setPropertyList(
field_url_columns = ['title | Base_getUrl',]) field_url_columns = ['title | Base_getUrl',])
...@@ -1816,7 +1813,6 @@ return url ...@@ -1816,7 +1813,6 @@ return url
@changeSkin('Hal') @changeSkin('Hal')
def test_getHateoasDocument_listbox_check_url_column_no_url(self): def test_getHateoasDocument_listbox_check_url_column_no_url(self):
self._makeDocument() self._makeDocument()
# pass custom list method which expect input arguments
self.portal.foo_module.FooModule_viewFooList.listbox.ListBox_setPropertyList( self.portal.foo_module.FooModule_viewFooList.listbox.ListBox_setPropertyList(
field_url_columns = ['title|',]) field_url_columns = ['title|',])
...@@ -1843,6 +1839,41 @@ return url ...@@ -1843,6 +1839,41 @@ return url
self.portal.foo_module.FooModule_viewFooList.listbox.ListBox_setPropertyList( self.portal.foo_module.FooModule_viewFooList.listbox.ListBox_setPropertyList(
field_url_columns = '') field_url_columns = '')
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasDocument_listbox_check_url_column_no_url_None(self):
# variation of test_getHateoasDocument_listbox_check_url_column_no_url here the
# "no url" is done by setting `None` in TALES expression, instead of '' that get
# set by formulator `key | value` syntax.
self._makeDocument()
self.portal.foo_module.FooModule_viewFooList.listbox.manage_tales_xmlrpc(
dict(url_columns='python: [("title", None), ]'))
fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(
REQUEST=fake_request,
mode="search",
list_method='contentValues',
relative_url='foo_module',
select_list=['id', 'title', 'creation_date', 'modification_date'],
form_relative_url='portal_skins/erp5_ui_test/FooModule_viewFooList/listbox')
result_dict = json.loads(result)
# Test the listbox_uid parameter
self.assertEqual(result_dict['_embedded']['contents'][0]['listbox_uid:list']['key'], 'listbox_uid:list')
# Test the URL value
self.assertEqual(result_dict['_embedded']['contents'][0]['title']['url_value'], {})
# Test if the value of the column is with right key
self.assertTrue(result_dict['_embedded']['contents'][0]['title']['default'])
# Reset the url_columns of the listbox
self.portal.foo_module.FooModule_viewFooList.listbox.manage_tales_xmlrpc(dict(url_columns=''))
@simulate('Base_getRequestUrl', '*args, **kwargs', @simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"') 'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
...@@ -1861,7 +1892,6 @@ return url ...@@ -1861,7 +1892,6 @@ return url
@changeSkin('Hal') @changeSkin('Hal')
def test_getHateoasDocument_listbox_check_url_column_option_parameters(self): def test_getHateoasDocument_listbox_check_url_column_option_parameters(self):
self._makeDocument() self._makeDocument()
# pass custom list method which expect input arguments
self.portal.foo_module.FooModule_viewFooList.listbox.ListBox_setPropertyList( self.portal.foo_module.FooModule_viewFooList.listbox.ListBox_setPropertyList(
field_url_columns = ['title | Base_getUrl',]) field_url_columns = ['title | Base_getUrl',])
......
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