Commit 6f380f30 authored by Sebastien Robin's avatar Sebastien Robin

better management of multi relation list


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@578 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9c146950
...@@ -95,9 +95,14 @@ try: ...@@ -95,9 +95,14 @@ try:
request.set('portal_type', portal_type) request.set('portal_type', portal_type)
request.set(my_field.get_value('catalog_index'), new_value) request.set(my_field.get_value('catalog_index'), new_value)
request.set('field_id', my_field.id) request.set('field_id', my_field.id)
uids = o.getValueUids(base_category, portal_type=portal_type) previous_uids = o.getValueUids(base_category, portal_type=portal_type)
context.portal_selections.setSelectionCheckedUidsFor('search_relation', uids)
relation_list = context.portal_catalog(**kw) relation_list = context.portal_catalog(**kw)
relation_uid_list = map(lambda x: x.uid, relation_list)
uids = []
for uid in previous_uids:
if uid in relation_uid_list:
uids.append(uid)
context.portal_selections.setSelectionCheckedUidsFor('search_relation', uids)
if len(new_value) == 0: if len(new_value) == 0:
# Clear the relation # Clear the relation
o.setValueUids(base_category, (), portal_type=portal_type) o.setValueUids(base_category, (), portal_type=portal_type)
...@@ -123,6 +128,29 @@ try: ...@@ -123,6 +128,29 @@ try:
uids = uids, uids = uids,
object_uid = object_uid, object_uid = object_uid,
listbox_uid=None) listbox_uid=None)
# This is just added when we want to just remove
# one item inside a multiRelationField
else:
if len(relation_uid_list) == len(new_value):
complete_value_list = []
# We have to find the full value, for example instead of
# /foo/ba% we should have /foo/bar
for value in new_value:
catalog_index = my_field.get_value('catalog_index')
kw[catalog_index] = value
complete_value = context.portal_catalog(**kw)[0][catalog_index]
complete_value_list.append(complete_value)
new_value = complete_value_list
uids = getOrderedUids(relation_uid_list, new_value, my_field.get_value('catalog_index'))
selection_index=None
return o.update_relation( form_id = form_id,
field_id = my_field.id,
selection_index = selection_index,
selection_name = selection_name,
uids = uids,
object_uid = object_uid,
listbox_uid=None)
kw = {} kw = {}
kw['form_id'] = 'search_relation' kw['form_id'] = 'search_relation'
kw['selection_index'] = selection_index kw['selection_index'] = selection_index
......
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