def option_has_other(self, answer_id, option_index): if not self.options_with_children: self.options_with_children = SchemaHelper.get_parent_options_for_block( self.block_json) if answer_id in self.options_with_children and self.options_with_children[ answer_id]['index'] == option_index: return True return False
def get_other_answer(self, answer_id, option_index): if not self.options_with_children: self.options_with_children = SchemaHelper.get_parent_options_for_block( self.block_json) if answer_id in self.options_with_children and self.options_with_children[ answer_id]['index'] == option_index: return getattr( self, self.options_with_children[answer_id]['child_answer_id']) return None
def test_get_parent_options_for_block(self): survey = load_schema_file("test_checkbox.json") block_json = SchemaHelper.get_block(survey, 'mandatory-checkbox') parent_options = SchemaHelper.get_parent_options_for_block(block_json) expected = { 'mandatory-checkbox-answer': { 'index': 6, 'child_answer_id': 'other-answer-mandatory' } } self.assertEqual(parent_options, expected)