Skip to content

Commit

Permalink
Update copy_field_values to return a list of values added to destinat…
Browse files Browse the repository at this point in the history
…ion field
  • Loading branch information
kolanos committed Jun 29, 2016
1 parent b3c8d2d commit e8c929f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name="swimlane",
author="Swimlane LLC",
author_email="[email protected]",
version="0.0.6",
version="0.0.7",
url="https://github.com/Swimlane/sw-python-client",
packages=find_packages(),
description="A Python client for Swimlane.",
Expand Down
8 changes: 7 additions & 1 deletion swimlane/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def copy_field_values(src_app, src_field_name, dest_app, dest_field_name):
:type dest_app: :class:`App`
:param dest_field_name: The name of the field to copy to.
:type dest_field_name: str
:returns: A list of values added to destination field.
:rtype: list
"""
if not isinstance(src_app, App):
raise TypeError('The src_app must be an instance of App')
Expand All @@ -85,10 +87,14 @@ def copy_field_values(src_app, src_field_name, dest_app, dest_field_name):
if src_field['fieldType'] != 'valuesList' or \
dest_field['fieldType'] != 'valuesList':
raise TypeError('Source and destination fields must be valuesList')
added_values = []
for src_value in src_field['values']:
dest_value = get_by_key_value(dest_field, 'name', src_value['name'])
if not dest_value:
dest_value = copy.deepcopy(src_value)
dest_value['id'] = random_objectid()
dest_field['values'].append(dest_value)
dest_app.save()
added_values.append(dest_value)
if added_values:
dest_app.save()
return added_values

0 comments on commit e8c929f

Please sign in to comment.