Skip to content

Commit

Permalink
Merge pull request #979 from onaio/fix-charts-list-has-no-split-attri…
Browse files Browse the repository at this point in the history
…bute-error

fix list has no split attribute exception in chart_tools.py
  • Loading branch information
ukanga authored Mar 30, 2017
2 parents 2c05587 + 924d0fa commit c4df244
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
14 changes: 14 additions & 0 deletions onadata/libs/tests/utils/test_chart_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,20 @@ def test_get_choice_label_with_single_select(self):

self.assertEqual(get_choice_label(choices, string), [string])

def test_get_choice_label_with_list_label(self):
choices = [{
'control': {},
'name': 'Western Rural',
'label': 'Western Rural'
}, {
'control': {},
'name': 'Western Urban',
'label': 'Western Urban'
}]
string = ['Western Rural']

self.assertEqual(get_choice_label(choices, [string]), [string])

def test_get_choice_label_for_multi_select(self):
pam = "PAM"
croix_rouge = "Croix Rouge"
Expand Down
5 changes: 4 additions & 1 deletion onadata/libs/utils/chart_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def get_choice_label(choices, string):
"""
labels = []

if string and choices:
if string and isinstance(string, six.string_types) and choices:
label = find_choice_label(choices, string)

if label:
Expand All @@ -122,6 +122,9 @@ def get_choice_label(choices, string):
# but a missing label, use string
if None in labels:
labels = [string]
elif isinstance(string, list) and string:
# most likely already translated
labels = string
elif not choices:
labels = [string]

Expand Down

0 comments on commit c4df244

Please sign in to comment.