Skip to content

Commit

Permalink
Add MULTIPLE_SELECT_TYPE and SELECT_BIND_TYPE tags
Browse files Browse the repository at this point in the history
Add MULTI_SELECT_TYPE and SELECT_BIND_TYPE tags removing the previously
used SELECT_ONE and SELECT_MULTIPLE variables. More info:
XLSForm/pyxform#410
  • Loading branch information
DavisRayM committed Feb 28, 2020
1 parent a192848 commit 46fd855
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
7 changes: 4 additions & 3 deletions onadata/apps/logger/models/xform.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
NOTES, SUBMISSION_TIME,
SUBMITTED_BY, TAGS, TOTAL_MEDIA,
UUID, VERSION, REVIEW_STATUS,
REVIEW_COMMENT)
REVIEW_COMMENT,
MULTIPLE_SELECT_TYPE)
from onadata.libs.utils.model_tools import queryset_iterator
from onadata.libs.utils.mongo import _encode_for_mongo

Expand Down Expand Up @@ -437,7 +438,8 @@ def xpaths(self,

# replace the single question column with a column for each
# item in a select all that apply question.
if survey_element.bind.get(u'type') == u'select':
if survey_element.bind.get(u'type') == u'string' \
and survey_element.type == MULTIPLE_SELECT_TYPE:
result.pop()
for child in survey_element.children:
result.append('/'.join([path, child.name]))
Expand Down Expand Up @@ -475,7 +477,6 @@ def get_headers(self, include_additional_headers=False):
"""
Return a list of headers for a csv file.
"""

def shorten(xpath):
xpath_list = xpath.split('/')
return '/'.join(xpath_list[2:])
Expand Down
1 change: 1 addition & 0 deletions onadata/libs/utils/common_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@

TEXTIT = 'textit'
OSM = 'osm'
SELECT_BIND_TYPE = 'string'
MULTIPLE_SELECT_TYPE = 'select all that apply'
GROUPNAME_REMOVED_FLAG = 'group-name-removed'
DATAVIEW_EXPORT = U'dataview'
Expand Down
7 changes: 5 additions & 2 deletions onadata/libs/utils/csv_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
SUBMISSION_TIME, SUBMITTED_BY,
TAGS, TOTAL_MEDIA, UUID, VERSION,
XFORM_ID_STRING, REVIEW_STATUS,
REVIEW_COMMENT)
REVIEW_COMMENT,
MULTIPLE_SELECT_TYPE,
SELECT_BIND_TYPE)
from onadata.libs.utils.export_builder import (get_choice_label,
get_value_or_attachment_uri,
track_task_progress)
Expand Down Expand Up @@ -222,7 +224,8 @@ def _collect_select_multiples(cls, dd, language=None):
select_multiples = []
select_multiple_elements = [
e for e in dd.get_survey_elements_with_choices()
if e.bind.get('type') == 'select'
if e.bind.get('type') == SELECT_BIND_TYPE
and e.type == MULTIPLE_SELECT_TYPE
]
for e in select_multiple_elements:
xpath = e.get_abbreviated_xpath()
Expand Down
15 changes: 7 additions & 8 deletions onadata/libs/utils/export_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@
from onadata.apps.viewer.models.data_dictionary import DataDictionary
from onadata.libs.utils.common_tags import (
ATTACHMENTS, BAMBOO_DATASET_ID, DELETEDAT, DURATION, GEOLOCATION,
ID, INDEX, MULTIPLE_SELECT_TYPE, NOTES, PARENT_INDEX,
ID, INDEX, MULTIPLE_SELECT_TYPE, SELECT_ONE, NOTES, PARENT_INDEX,
PARENT_TABLE_NAME, REPEAT_INDEX_TAGS, SAV_255_BYTES_TYPE,
SAV_NUMERIC_TYPE, STATUS, SUBMISSION_TIME, SUBMITTED_BY, TAGS, UUID,
VERSION, XFORM_ID_STRING, REVIEW_STATUS, REVIEW_COMMENT)
VERSION, XFORM_ID_STRING, REVIEW_STATUS, REVIEW_COMMENT, SELECT_BIND_TYPE)
from onadata.libs.utils.mongo import _decode_from_mongo, _is_invalid_for_mongo

# the bind type of select multiples that we use to compare
MULTIPLE_SELECT_BIND_TYPE = 'select'
SELECT_ONE_BIND_TYPE = 'select1'
GEOPOINT_BIND_TYPE = 'geopoint'
OSM_BIND_TYPE = 'osm'
DEFAULT_UPDATE_BATCH = 100
Expand Down Expand Up @@ -475,7 +472,8 @@ def build_sections(
{child_xpath: _encode_for_mongo(child_xpath)})

# if its a select multiple, make columns out of its choices
if child.bind.get('type') == MULTIPLE_SELECT_BIND_TYPE:
if child.bind.get('type') == SELECT_BIND_TYPE \
and child.type == MULTIPLE_SELECT_TYPE:
choices = []
if self.SPLIT_SELECT_MULTIPLES:
choices = self._get_select_mulitples_choices(
Expand Down Expand Up @@ -527,7 +525,8 @@ def build_sections(
_append_xpaths_to_section(
current_section_name, osm_fields,
child.get_abbreviated_xpath(), xpaths)
if child.bind.get(u"type") == SELECT_ONE_BIND_TYPE:
if child.bind.get(u"type") == SELECT_BIND_TYPE \
and child.type == SELECT_ONE:
_append_xpaths_to_section(
current_section_name, select_ones,
child.get_abbreviated_xpath(), [])
Expand Down Expand Up @@ -1062,7 +1061,7 @@ def _is_numeric(xpath, element_type, data_dictionary):
parent_xpath = '/'.join(xpath.split('/')[:-1])
parent = data_dictionary.get_element(parent_xpath)
return (parent and parent.type == MULTIPLE_SELECT_TYPE)
elif element_type != SELECT_ONE_BIND_TYPE:
elif element_type != 'select1':
return False

if var_name not in all_value_labels:
Expand Down

0 comments on commit 46fd855

Please sign in to comment.