Commit a26aa2dd authored by Tomáš Peterka's avatar Tomáš Peterka

WIP

parent 7b8798f3
......@@ -9,10 +9,12 @@ In general it always returns a JSON reponse in HATEOAS format specification.
:param relative_url: an URL of `traversed_document` to operate on (it must have an object_view)
Only in mode == 'search'
:param query:
:param select_list:
:param limit:tr
:param query: string-serialized Query
:param select_list: list of strings to select from search result object
:param limit: tuple(start_index, num_records) which is further passed to list_method BUT not every list_method takes it into account
:param form_relative_url: {str} relative URL of a form FIELD issuing the search (listbox/relation field...)
it can be None in case of special listboxes like List of Modules
or relative path like "portal_skins/erp5_ui_test/FooModule_viewFooList/listbox"
Only in mode == 'form'
:param form:
......@@ -1421,15 +1423,18 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
elif same_type(select_list, ""):
select_list = [select_list]
# form field issuing this search
source_field = portal.restrictedTraverse(form_relative_url) if form_relative_url else None
# extract form field definition into `editable_field_dict`
editable_field_dict = {}
listbox_form = None
listbox_field_id = None
if form_relative_url is not None:
listbox_field = portal.restrictedTraverse(form_relative_url)
listbox_field_id = listbox_field.id
if source_field is not None and source_field.meta_type == "ListBox":
listbox_field_id = source_field.id
# XXX Proxy field are not correctly handled in traversed_document of web site
listbox_form = getattr(traversed_document, listbox_field.aq_parent.id)
listbox_form = getattr(traversed_document, source_field.aq_parent.id)
for select in select_list:
# See Listbox.py getValueList --> getEditableField & getColumnAliasList method
# In short: there are Form Field definitions which names start with
......@@ -1464,9 +1469,8 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
# this dict will hold all resolved values
contents_item = {
# _links.self.href is mandatory for JIO so it can create reference to the
# (listbox) item alone
'_links': {
# _links.self.href is mandatory for JIO so it can create reference to items alone
'self': {
"href": default_document_uri_template % {
"root_url": site_root.absolute_url(),
......@@ -1524,6 +1528,32 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
}
})
# Compute statistics if the search issuer was ListBox
# or in future if the stats (SUM) are required by JIO call
contents_stat_list = []
if source_field is not None and source_field.meta_type == "ListBox":
# in case the search was issued by listbox we can provide results of
# stat_method and count_method back to the caller
# XXX: we should check whether they asked for it
stat_method = source_field.get_value('stat_method')
stat_columns = source_field.get_value('stat_columns')
contents_stat = {}
if len(stat_columns) > 0:
# prefer stat per columns as it is in ListBox
# always called on current context
for stat_name, stat_script in stat_columns:
contents_stat[stat_name] = getattr(traversed_document, stat_script)(**catalog_kw)
contents_stat_list.append(contents_stat)
elif stat_method != "" and stat_method.getMethodName() != list_method_name:
# global stat_method is second - should return dictionary or list of dictionaries
# where all "fields" should be accessible by its "select" name
contents_stat_list = getattr(traversed_document, stat_method.getMethodName())(**catalog_kw)
if len(contents_stat_list) > 0:
result_dict['_embedded'].update({
'contents': contents_list
})
# We should cleanup the selection if it exists in catalog params BUT
# we cannot because it requires escalated Permission.'modifyPortal' so
# the correct solution would be to ReportSection.popReport but unfortunately
......
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