def update_questionnaire_store_with_form_data(questionnaire_store, location, answer_dict): survey_answer_ids = SchemaHelper.get_answer_ids_for_location(g.schema_json, location) for answer_id, answer_value in answer_dict.items(): if answer_id in survey_answer_ids or location.block_id == 'household-composition': answer = None # Dates are comprised of 3 string values if isinstance(answer_value, dict): is_day_month_year = 'day' in answer_value and 'month' in answer_value is_month_year = 'year' in answer_value and 'month' in answer_value if is_day_month_year and answer_value['day'] and answer_value['month']: date_str = "{:02d}/{:02d}/{}".format( int(answer_value['day']), int(answer_value['month']), answer_value['year'], ) answer = Answer(answer_id=answer_id, value=date_str, location=location) elif is_month_year and answer_value['month']: date_str = "{:02d}/{}".format(int(answer_value['month']), answer_value['year']) answer = Answer(answer_id=answer_id, value=date_str, location=location) elif answer_value != 'None' and answer_value is not None: # Necessary because default select casts to string value 'None' answer = Answer(answer_id=answer_id, value=answer_value, location=location) if answer: questionnaire_store.answer_store.add_or_update(answer) if location not in questionnaire_store.completed_blocks: questionnaire_store.completed_blocks.append(location)
def update_questionnaire_store_with_form_data(questionnaire_store, location, answer_dict): survey_answer_ids = SchemaHelper.get_answer_ids_for_location( g.schema_json, location) for answer_id, answer_value in answer_dict.items(): if answer_id in survey_answer_ids or location.block_id == 'household-composition': answer = None # Dates are comprised of 3 string values if isinstance(answer_value, dict): if answer_value_empty(answer_value): _remove_answer_from_questionnaire_store( answer_id, location, questionnaire_store) else: formatted_answer_value = _format_answer_value(answer_value) if formatted_answer_value: answer = Answer(answer_id=answer_id, value=formatted_answer_value, location=location) elif answer_value is not None: answer = Answer(answer_id=answer_id, value=answer_value, location=location) else: _remove_answer_from_questionnaire_store( answer_id, location, questionnaire_store) if answer: questionnaire_store.answer_store.add_or_update(answer) if location not in questionnaire_store.completed_blocks: questionnaire_store.completed_blocks.append(location)
def update_questionnaire_store_with_answer_data(questionnaire_store, location, answers): survey_answer_ids = SchemaHelper.get_answer_ids_for_location(g.schema_json, location) for answer in [a for a in answers if a.answer_id in survey_answer_ids]: questionnaire_store.answer_store.add_or_update(answer) if location not in questionnaire_store.completed_blocks: questionnaire_store.completed_blocks.append(location)