Commit ef67acec authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[trac384] fix the two 'types' of default

When the default for an element is asked, and the element is one in a
list, there are two options; a list can have a default value (like an
empty list), but its elements can have their own default values. This
change makes it so that if the current value of a list is its default,
it'll find the element in there. If the list is *not* the default, it'll
return the default for the element itself (i.e. an element has been
added to a list, but not all of the elements values have been set)
parent 184c6c70
......@@ -378,24 +378,34 @@ class MultiConfigData:
while len(id_parts) > 0:
id_part = id_parts.pop(0)
item_id, list_indices = isc.cc.data.split_identifier_list_indices(id_part)
id_list = module + "/" + id_prefix + "/" + item_id
id_prefix += "/" + id_part
if list_indices is not None:
spec = find_spec_part(self._specifications[module].get_config_spec(), id_prefix)
if 'item_default' in spec:
list_value = spec['item_default']
for i in list_indices:
if i < len(list_value):
list_value = list_value[i]
# there's actually two kinds of default here for
# lists; they can have a default value (like an
# empty list), but their elements can also have
# default values.
# So if the list item *itself* is a default,
# we need to get the value out of that. If not, we
# need to find the default for the specific element.
list_value, type = self.get_value(id_list)
list_spec = find_spec_part(self._specifications[module].get_config_spec(), id_prefix)
if type == self.DEFAULT:
if 'item_default' in list_spec:
list_value = list_spec['item_default']
for i in list_indices:
if i < len(list_value):
list_value = list_value[i]
else:
# out of range, return None
return None
if len(id_parts) > 0:
rest_of_id = "/".join(id_parts)
return isc.cc.data.find(list_value, rest_of_id)
else:
# out of range, return None
return None
if len(id_parts) > 0:
rest_of_id = "/".join(id_parts)
return isc.cc.data.find(list_value, rest_of_id)
else:
return list_value
return list_value
spec = find_spec_part(self._specifications[module].get_config_spec(), id)
if 'item_default' in spec:
return spec['item_default']
......
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