Commit b4f0c21b authored by Romain Courteaud's avatar Romain Courteaud

[erp5_hal_json_style] Render domain tree for each listbox

parent 37fa9e68
......@@ -148,6 +148,54 @@ def ensureDeserialized(obj):
return datetime.time(*tuple(map(int, match_obj.groups())))
return obj
NBSP_UTF8 = u'\xA0'.encode('utf-8')
def generateDomainTreeList(url_tool, domain_tool, domain, depth, domain_list):
if depth:
domain_list.append((
'%s%s' % (NBSP_UTF8 * 4 * (depth - 1), domain.getTitle()),
'/'.join(url_tool.getRelativeContentPath(domain)[2:])
))
new_depth = depth + 1
for sub_domain in domain_tool.getChildDomainValueList(domain, depth=depth):
generateDomainTreeList(url_tool, domain_tool, sub_domain, new_depth, domain_list)
def getDomainSelection(domain_list):
root_dict = {}
if len(domain_list) > 0:
category_tool = portal.portal_categories
domain_tool = portal.portal_domains
preference_tool = portal.portal_preferences
url_tool = portal.portal_url
for base_domain_id in domain_list:
domain = None
if category_tool is not None:
domain = category_tool.restrictedTraverse(base_domain_id, None)
if domain is not None :
root_dict[base_domain_id] = getattr(
domain,
preference_tool.getPreference(
'preferred_category_child_item_list_method_id',
'getCategoryChildCompactLogicalPathItemList'
)
)(local_sort_id=('int_index', 'translated_title'), checked_permission='View',
filter_node=0, display_none_category=0)
elif domain_tool is not None:
try:
domain = domain_tool.getDomainByPath(base_domain_id, None)
except KeyError:
domain = None
if domain is not None:
# XXX Implement recursive fetch
domain_list = []
generateDomainTreeList(url_tool, domain_tool, domain, 0, domain_list)
root_dict[base_domain_id] = domain_list
return root_dict
def getProtectedProperty(document, select):
"""getProtectedProperty is a security-aware substitution for builtin `getattr`
......@@ -803,8 +851,11 @@ def renderField(traversed_document, field, form, value=None, meta_type=None, key
"query": make_query({
"query": sql_catalog.buildQuery(
list_method_query_dict,
ignore_unknown_columns=True).asSearchTextExpression(sql_catalog)})}
ignore_unknown_columns=True).asSearchTextExpression(sql_catalog)})},
"domain_root_list": field.get_value("domain_root_list")
})
result["domain_dict"] = getDomainSelection([x[0] for x in result["domain_root_list"]])
if (list_method_custom is not None):
result["list_method_template"] = list_method_custom
return result
......
......@@ -536,7 +536,8 @@ class TestERP5Document_getHateoas_mode_traverse(ERP5HALJSONStyleSkinsMixin):
field_editable = 1,
field_columns = 'id|ID\ntitle|Title\nquantity|Quantity\nstart_date|Date\ncatalog.uid|Uid',
field_editable_columns = 'id|ID\ntitle|Title\nquantity|quantity\nstart_date|Date',
field_search_columns = 'id|ID\ntitle|Title\nquantity|Quantity\nstart_date|Date',)
field_search_columns = 'id|ID\ntitle|Title\nquantity|Quantity\nstart_date|Date',
field_domain_root_list = 'foo_category|FooCat\nfoo_domain|FooDomain\nnot_existing_domain|NotExisting',)
parent = document.getParentValue()
fake_request = do_fake_request("GET")
......@@ -630,6 +631,9 @@ class TestERP5Document_getHateoas_mode_traverse(ERP5HALJSONStyleSkinsMixin):
self.assertEqual(result_dict['_embedded']['_view']['listbox']['sort_column_list'], [['id', 'ID'], ['title', 'Title'], ['quantity', 'Quantity'], ['start_date', 'Date']])
self.assertEqual(result_dict['_embedded']['_view']['listbox']['list_method_template'],
'%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=search&relative_url=foo_module%%2F%s&form_relative_url=portal_skins/erp5_ui_test/Foo_view/listbox&list_method=objectValues&default_param_json=eyJwb3J0YWxfdHlwZSI6IFsiRm9vIExpbmUiXSwgImlnbm9yZV91bmtub3duX2NvbHVtbnMiOiB0cnVlfQ=={&query,select_list*,limit*,sort_on*,local_roles*,selection_domain*}' % (self.portal.absolute_url(), document.getId()))
self.assertEqual(result_dict['_embedded']['_view']['listbox']['domain_root_list'], [['foo_category', 'FooCat'], ['foo_domain', 'FooDomain'], ['not_existing_domain', 'NotExisting']])
NBSP_prefix = u'\xA0' * 4
self.assertEqual(result_dict['_embedded']['_view']['listbox']['domain_dict'], {'foo_domain': [['a', 'a'], ['%sa1' % NBSP_prefix, 'a/a1'], ['%sa2' % NBSP_prefix, 'a/a2'], ['b', 'b']], 'foo_category': [['a', 'a'], ['a/a1', 'a/a1'], ['a/a2', 'a/a2'], ['b', 'b']]})
self.assertEqual(result_dict['_embedded']['_view']['_links']['traversed_document']['href'], 'urn:jio:get:%s' % document.getRelativeUrl())
self.assertEqual(result_dict['_embedded']['_view']['_links']['traversed_document']['name'], document.getRelativeUrl())
......
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