Commit e1a07bc5 authored by Leonardo Rochael Almeida's avatar Leonardo Rochael Almeida Committed by Julien Muchembled

When building, edit changes in the right order

The builder was taking a carefully ordered list of movement group nodes and
their suggested changes, and squashing the changes all together in a single
dictionary for .edit(**kw).

Now we calculate the edit_order to take the movement_group order into account.
parent 998bb1c3
......@@ -277,27 +277,39 @@ class BuilderMixin(XMLObject, Amount, Predicate):
def _test(self, instance, movement_group_node_list,
result = True
new_property_dict = {}
new_property_dict_list = []
for movement_group_node in movement_group_node_list:
tmp_result, tmp_property_dict = movement_group_node.test(
instance, divergence_list)
if not tmp_result:
result = tmp_result
return result, new_property_dict
return result, new_property_dict_list
def _getSortedPropertyDict(property_dict_list):
# Sort the edit keywords according to the order of their movement
# groups. This is important so that, for example, the 'resource'
# is already set on a movement before trying to set the
# 'variation_category' or 'variation_property' pseudo properties,
# which rely on the resource being set to discover which
# categories/properties to set
# XXX-Leo: in the future: using an ordered_dict would be nice,
# but this would have to be respected on Base._edit()
edit_order = []
property_dict = {'edit_order': edit_order}
for d in property_dict_list:
for k,v in d.iteritems():
if k in property_dict:
raise DuplicatedPropertyDictKeysError(k)
property_dict[k] = v
return property_dict
def _findUpdatableObject(self, instance_list, movement_group_node_list,
instance = None
property_dict = {}
if not len(instance_list):
for movement_group_node in movement_group_node_list:
for k,v in movement_group_node.getGroupEditDict().iteritems():
if k in property_dict:
raise DuplicatedPropertyDictKeysError(k)
property_dict[k] = v
if instance_list:
# we want to check the original delivery first.
# so sort instance_list by that current is exists or not.
......@@ -311,12 +323,15 @@ class BuilderMixin(XMLObject, Amount, Predicate):
except AttributeError:
for instance_to_update in instance_list:
result, property_dict = self._test(
result, property_dict_list = self._test(
instance_to_update, movement_group_node_list, divergence_list)
if result:
instance = instance_to_update
return instance, property_dict
property_dict_list = [movement_group_node.getGroupEditDict()
for movement_group_node in movement_group_node_list]
return instance, self._getSortedPropertyDict(property_dict_list)
def buildDeliveryList(self, movement_group_node,
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment