def create_survey_element_from_dict(self, d): """ Convert from a nested python dictionary/array structure (a json dict I call it because it corresponds directly with a json object) to a survey object """ if u"add_none_option" in d: self._add_none_option = d[u"add_none_option"] if d[u"type"] in self.SECTION_CLASSES: return self._create_section_from_dict(d) elif d[u"type"] == u"loop": return self._create_loop_from_dict(d) elif d[u"type"] == u"include": section_name = d[u"name"] if section_name not in self._sections: raise PyXFormError("This section has not been included.", section_name, self._sections.keys()) d = self._sections[section_name] full_survey = self.create_survey_element_from_dict(d) return full_survey.children elif d[u"type"] == u"xml-external": return ExternalInstance(**d) else: return self._create_question_from_dict( d, copy_json_dict(QUESTION_TYPE_DICT), self._add_none_option)
def create_survey_element_from_dict(self, d): """ Convert from a nested python dictionary/array structure (a json dict I call it because it corresponds directly with a json object) to a survey object """ if "add_none_option" in d: self._add_none_option = d["add_none_option"] if d["type"] in self.SECTION_CLASSES: section = self._create_section_from_dict(d) if d["type"] == "survey": section.setvalues_by_triggering_ref = self.setvalues_by_triggering_ref return section elif d["type"] == "loop": return self._create_loop_from_dict(d) elif d["type"] == "include": section_name = d["name"] if section_name not in self._sections: raise PyXFormError( "This section has not been included.", section_name, self._sections.keys(), ) d = self._sections[section_name] full_survey = self.create_survey_element_from_dict(d) return full_survey.children elif d["type"] in ["xml-external", "csv-external"]: return ExternalInstance(**d) else: self._save_trigger_as_setvalue_and_remove_calculate(d) return self._create_question_from_dict( d, copy_json_dict(QUESTION_TYPE_DICT), self._add_none_option)