Commit df2cf859 authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_hal_json_style: add sort functionnality

parent 1b6fd549
...@@ -73,13 +73,14 @@ return context.ERP5Document_getHateoas(\n ...@@ -73,13 +73,14 @@ return context.ERP5Document_getHateoas(\n
default_param_json=default_param_json,\n default_param_json=default_param_json,\n
form_relative_url=form_relative_url,\n form_relative_url=form_relative_url,\n
bulk_list=bulk_list,\n bulk_list=bulk_list,\n
sort_on=sort_on,\n
restricted=1\n restricted=1\n
)\n )\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, form=None, relative_url=None, list_method=None, default_param_json=None, form_relative_url=None, bulk_list="[]"</string> </value> <value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, form=None, relative_url=None, list_method=None, default_param_json=None, form_relative_url=None, bulk_list="[]", sort_on=None</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -75,18 +75,18 @@ url_template_dict = {\n ...@@ -75,18 +75,18 @@ url_template_dict = {\n
"traverse_template": "%(root_url)s/%(script_id)s?mode=traverse" + \\\n "traverse_template": "%(root_url)s/%(script_id)s?mode=traverse" + \\\n
"{&relative_url,view}",\n "{&relative_url,view}",\n
"search_template": "%(root_url)s/%(script_id)s?mode=search" + \\\n "search_template": "%(root_url)s/%(script_id)s?mode=search" + \\\n
"{&query,select_list*,limit*}",\n "{&query,select_list*,limit*,sort_on*}",\n
"custom_search_template": "%(root_url)s/%(script_id)s?mode=search" + \\\n "custom_search_template": "%(root_url)s/%(script_id)s?mode=search" + \\\n
"&relative_url=%(relative_url)s" \\\n "&relative_url=%(relative_url)s" \\\n
"&form_relative_url=%(form_relative_url)s" \\\n "&form_relative_url=%(form_relative_url)s" \\\n
"&list_method=%(list_method)s" \\\n "&list_method=%(list_method)s" \\\n
"&default_param_json=%(default_param_json)s" \\\n "&default_param_json=%(default_param_json)s" \\\n
"{&query,select_list*,limit*}",\n "{&query,select_list*,limit*,sort_on*}",\n
"custom_search_template_no_editable": "%(root_url)s/%(script_id)s?mode=search" + \\\n "custom_search_template_no_editable": "%(root_url)s/%(script_id)s?mode=search" + \\\n
"&relative_url=%(relative_url)s" \\\n "&relative_url=%(relative_url)s" \\\n
"&list_method=%(list_method)s" \\\n "&list_method=%(list_method)s" \\\n
"&default_param_json=%(default_param_json)s" \\\n "&default_param_json=%(default_param_json)s" \\\n
"{&query,select_list*,limit*}",\n "{&query,select_list*,limit*,sort_on*}",\n
"new_content_action": "%(root_url)s/%(script_id)s?mode=newContent",\n "new_content_action": "%(root_url)s/%(script_id)s?mode=newContent",\n
"bulk_action": "%(root_url)s/%(script_id)s?mode=bulk",\n "bulk_action": "%(root_url)s/%(script_id)s?mode=bulk",\n
# XXX View is set by default to empty\n # XXX View is set by default to empty\n
...@@ -901,11 +901,18 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -901,11 +901,18 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
callable_list_method = portal.portal_catalog\n callable_list_method = portal.portal_catalog\n
else:\n else:\n
callable_list_method = getattr(traversed_document, list_method)\n callable_list_method = getattr(traversed_document, list_method)\n
\n
tmp_sort_on = ()\n
if sort_on is not None:\n
for grain in sort_on:\n
if grain != "":\n
tmp_sort_on += (tuple([x for x in grain.split(",")]),)\n
\n
if query:\n if query:\n
sql_list = callable_list_method(full_text=query, limit=limit, **catalog_kw)\n sql_list = callable_list_method(full_text=query, limit=limit, sort_on=tmp_sort_on, **catalog_kw)\n
else:\n else:\n
sql_list = callable_list_method(limit=limit, **catalog_kw)\n sql_list = callable_list_method(limit=limit, sort_on=tmp_sort_on, **catalog_kw)\n
\n \n
result_list = []\n result_list = []\n
\n \n
# if (select_list is None):\n # if (select_list is None):\n
...@@ -1061,7 +1068,7 @@ else:\n ...@@ -1061,7 +1068,7 @@ else:\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, form=None, relative_url=None, restricted=0, list_method=None, default_param_json=None, form_relative_url=None, bulk_list="[]"</string> </value> <value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, form=None, relative_url=None, restricted=0, list_method=None, default_param_json=None, form_relative_url=None, bulk_list="[]", sort_on=()</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -348,7 +348,7 @@ class TestERP5Document_getHateoas_mode_root(ERP5HALJSONStyleSkinsMixin): ...@@ -348,7 +348,7 @@ class TestERP5Document_getHateoas_mode_root(ERP5HALJSONStyleSkinsMixin):
self.assertEqual(result_dict['_links']['type']['name'], document.getPortalType()) self.assertEqual(result_dict['_links']['type']['name'], document.getPortalType())
self.assertEqual(result_dict['_links']['raw_search']['href'], self.assertEqual(result_dict['_links']['raw_search']['href'],
"%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=search{&query,select_list*,limit*}" % self.portal.absolute_url()) "%s/web_site_module/hateoas/ERP5Document_getHateoas?mode=search{&query,select_list*,limit*,sort_on*}" % self.portal.absolute_url())
self.assertEqual(result_dict['_links']['raw_search']['templated'], True) self.assertEqual(result_dict['_links']['raw_search']['templated'], True)
self.assertEqual(result_dict['_links']['raw_search']['name'], "Raw Search") self.assertEqual(result_dict['_links']['raw_search']['name'], "Raw Search")
......
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