Skip to content

Commit

Permalink
Corrected bug when a parent field is multivalued.
Browse files Browse the repository at this point in the history
  • Loading branch information
sgeulette committed Feb 21, 2019
1 parent 065e117 commit 79dd536
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions CHANGES.rst
Expand Up @@ -4,8 +4,8 @@ Changelog
3.0.3 (unreleased)
------------------

- Nothing changed yet.

- Corrected bug when a parent field is multivalued.
[sgeulette]

3.0.2 (2018-08-22)
------------------
Expand Down
6 changes: 4 additions & 2 deletions src/collective/task/adapters.py
Expand Up @@ -145,8 +145,10 @@ def calculate_parents_value(self, field, p_fields):
new_value += [val for val in getattr(parent, field) if val not in new_value]
# we add parent field value
parent_value = base_hasattr(parent, dic['at']) and getattr(parent, dic['at']) or None
if parent_value and parent_value not in new_value:
new_value.append(parent_value)
if parent_value:
if not isinstance(parent_value, (list, tuple)):
parent_value = [parent_value]
new_value += [val for val in parent_value if val not in new_value]
return new_value

def set_parents_value(self, attr, value, modified=False):
Expand Down
6 changes: 5 additions & 1 deletion src/collective/task/tests/test_adapters.py
Expand Up @@ -59,14 +59,18 @@ def test_calculate_parents_value(self):
self.task4.assigned_group = 'Site Administrators'
self.assertListEqual(adapted.calculate_parents_value('parents_assigned_groups', attributes),
['Site Administrators'])
# a parent attribute contains multiple values
self.task4.assigned_group = ['Site Administrators', 'Administrators']
self.assertListEqual(adapted.calculate_parents_value('parents_assigned_groups', attributes),
['Site Administrators', 'Administrators'])
# an item is the same
self.task4.parents_assigned_groups = ['Administrators', 'Reviewers']
self.task4.assigned_group = 'Administrators'
self.assertListEqual(adapted.calculate_parents_value('parents_assigned_groups', attributes),
['Administrators', 'Reviewers'])
# full infos
self.task4.parents_assigned_groups = ['Administrators', 'Reviewers']
self.task4.assigned_group = 'Site Administrators'
self.task4.assigned_group = ['Site Administrators', 'Administrators']
self.assertListEqual(adapted.calculate_parents_value('parents_assigned_groups', attributes),
['Administrators', 'Reviewers', 'Site Administrators'])

Expand Down

0 comments on commit 79dd536

Please sign in to comment.