Skip to content

Commit

Permalink
Merge pull request #868 from onaio/allow-group-by-on-submitted-by-field
Browse files Browse the repository at this point in the history
include submitted by in the allowed group by fields
  • Loading branch information
pld authored Jan 12, 2017
2 parents 79f95b2 + 5db444d commit 95aa99a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 12 additions & 0 deletions onadata/libs/tests/utils/test_chart_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ def test_build_chart_data_for_field_on_submitted_by(self):
self.assertEqual(data['field_type'], 'text')
self.assertEqual(data['data_type'], 'categorized')

def test_build_chart_data_for_field_on_submitted_by_group_by(self):
group_by_field = find_field_by_name(self.xform, 'pizza_fan')
data = build_chart_data_for_field(self.xform, '_submitted_by',
group_by=group_by_field)
self.assertEqual(data['field_name'], '_submitted_by')
self.assertEqual(data['field_type'], 'text')
self.assertEqual(data['data_type'], 'categorized')
self.assertEqual(data['grouped_by'], u'pizza_fan')
self.assertEqual(data['data'],
[{'_submitted_by': u'bob',
'items': [{'count': 2L, u'pizza_fan': [u'No']}]}])

def test_build_chart_data_for_field_on_duration(self):
group_by_field = find_field_by_name(self.xform, 'pizza_fan')
data = build_chart_data_for_field(self.xform, '_duration',
Expand Down
5 changes: 3 additions & 2 deletions onadata/libs/utils/chart_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,9 @@ def build_chart_data_for_field(xform, field, language_index=0, choices=None,
group_by_name = group_by.get_abbreviated_xpath() \
if not isinstance(group_by, basestring) else group_by

if field_type == common_tags.SELECT_ONE \
and group_by.type == common_tags.SELECT_ONE:
if (field_type == common_tags.SELECT_ONE or
field_name == common_tags.SUBMITTED_BY) and \
group_by.type == common_tags.SELECT_ONE:
result = get_form_submissions_grouped_by_select_one(
xform, field_xpath, group_by_name, field_name, data_view)

Expand Down

0 comments on commit 95aa99a

Please sign in to comment.