Commit f22dd2f2 authored by Tomáš Peterka's avatar Tomáš Peterka Committed by Eteri

[erp5_hal_json_style] Refactor part of ERP5Document_getHateoas.py to be more readable

parent 0ffbfbfe
...@@ -113,7 +113,7 @@ def renderField(traversed_document, field, form_relative_url, value=None, meta_t ...@@ -113,7 +113,7 @@ def renderField(traversed_document, field, form_relative_url, value=None, meta_t
"required": field.get_value("required"), "required": field.get_value("required"),
# XXX Message can not be converted to json as is # XXX Message can not be converted to json as is
"items": field.get_value("items"), "items": field.get_value("items"),
"first_item": field.get_value("first_item") "first_item": field.get_value("first_item"),
} }
result["default"] = getFieldDefault(traversed_document, field, result["key"], value) result["default"] = getFieldDefault(traversed_document, field, result["key"], value)
elif meta_type == "RadioField": elif meta_type == "RadioField":
...@@ -342,48 +342,30 @@ def renderField(traversed_document, field, form_relative_url, value=None, meta_t ...@@ -342,48 +342,30 @@ def renderField(traversed_document, field, form_relative_url, value=None, meta_t
} }
result["default"] = getFieldDefault(traversed_document, field, result["key"], value) result["default"] = getFieldDefault(traversed_document, field, result["key"], value)
elif meta_type == "ListBox": elif meta_type == "ListBox":
# XXX Not implemented """Display list of objects with optional search/sort capabilities on columns from catalog."""
column_list = [] _translate = Base_translateString
for tmp in field.get_value("columns"):
column_list.append((tmp[0], Base_translateString(tmp[1]))) column_list = [(name, _translate(title)) for name, title in field.get_value("columns")]
editable_column_list = [] editable_column_list = [(name, _translate(title)) for name, title in field.get_value("editable_columns")]
for tmp in field.get_value('editable_columns'): catalog_column_list = [(name, title)
editable_column_list.append((tmp[0], Base_translateString(tmp[1]))) for name, title in column_list
if sql_catalog.isValidColumn(name)]
sort_column_list_tmp = []
# try to get specified searchable columns and fail back to all searchable columns
for tmp in field.get_value('sort_columns'): search_column_list = [(name, _translate(title))
sort_column_list_tmp.append((tmp[0], Base_translateString(tmp[1]))) for name, title in field.get_value("search_columns")
if sql_catalog.isValidColumn(name)] or catalog_column_list
search_column_list_tmp = []
for tmp in field.get_value('search_columns'): # try to get specified sortable columns and fail back to searchable fields
search_column_list_tmp.append((tmp[0], Base_translateString(tmp[1]))) sort_column_list = [(name, _translate(title))
for name, title in field.get_value("sort_columns")
sort_column_list = [] if sql_catalog.isValidColumn(name)] or search_column_list
search_column_list = []
# requirement: get only sortable/searchable columns which are already displayed in listbox
#only get sortable&searchable column which is already displayed in listbox # see https://lab.nexedi.com/nexedi/erp5/blob/HEAD/product/ERP5Form/ListBox.py#L1004
#see https://lab.nexedi.com/nexedi/erp5/blob/HEAD/product/ERP5Form/ListBox.py#L1004 # implemented in javascript in the end
# see https://lab.nexedi.com/nexedi/erp5/blob/master/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_listbox_js.js#L163
if search_column_list_tmp:
search_column_list = search_column_list_tmp
else:
for grain in column_list:
if sql_catalog.isValidColumn(grain[0]):
search_column_list.append(grain)
if sort_column_list_tmp:
sort_column_list = sort_column_list_tmp
else:
sort_column_list = search_column_list
# XXX
# list_method = getattr(traversed_document, traversed_document.Listbox_getListMethodName(field))
# portal_types = [x[1] for x in field.get_value('portal_types')]
portal_types = field.get_value('portal_types') portal_types = field.get_value('portal_types')
default_params = dict(field.get_value('default_params')) default_params = dict(field.get_value('default_params'))
default_params['ignore_unknown_columns'] = True default_params['ignore_unknown_columns'] = True
...@@ -445,19 +427,17 @@ def renderField(traversed_document, field, form_relative_url, value=None, meta_t ...@@ -445,19 +427,17 @@ def renderField(traversed_document, field, form_relative_url, value=None, meta_t
result = { result = {
"type": meta_type, "type": meta_type,
"editable": field.get_value("editable"), "editable": field.get_value("editable"),
# "column_list": [x[1] for x in columns],
"column_list": column_list, "column_list": column_list,
"search_column_list": search_column_list, "search_column_list": search_column_list,
"sort_column_list": sort_column_list, "sort_column_list": sort_column_list,
"editable_column_list": editable_column_list, "editable_column_list": editable_column_list,
"show_anchor": field.get_value("anchor"), "show_anchor": field.get_value("anchor"),
# "line_list": line_list,
"title": Base_translateString(field.get_value("title")), "title": Base_translateString(field.get_value("title")),
"key": key, "key": key,
"portal_type": portal_types, "portal_type": portal_types,
"lines": lines, "lines": lines,
"default_params": default_params, "default_params": default_params,
"list_method": list_method_name "list_method": list_method_name,
} }
if (list_method_custom is not None): if (list_method_custom is not None):
result["list_method_template"] = list_method_custom result["list_method_template"] = list_method_custom
......
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