Ejemplo n.º 1
0
def _create_or_get_survey_node(session, survey_node_dict, repeatable=None):
    node_dict = survey_node_dict['node']
    if 'id' in node_dict:
        node = get_model(session, Node, node_dict['id'])
    else:
        choices = node_dict.get('choices', None)
        if choices is not None:
            node_dict['choices'] = [Choice(**choice) for choice in choices]
        node = construct_node(**node_dict)
    survey_node_dict['node'] = node
    if repeatable is not None:
        survey_node_dict['repeatable'] = repeatable
    _css = _create_sub_survey
    sub_survey_data = survey_node_dict.get('sub_surveys', None)
    if sub_survey_data is not None:
        survey_node_dict['sub_surveys'] = [
            _css(session, ssd, node) for ssd in sub_survey_data
        ]
    return construct_survey_node(**survey_node_dict)
Ejemplo n.º 2
0
def _create_or_get_survey_node(session, survey_node_dict, repeatable=None):
    node_dict = survey_node_dict['node']
    if 'id' in node_dict:
        node = get_model(session, Node, node_dict['id'])
    else:
        choices = node_dict.get('choices', None)
        if choices is not None:
            node_dict['choices'] = [
                Choice(**choice) for choice in choices
            ]
        node = construct_node(**node_dict)
    survey_node_dict['node'] = node
    if repeatable is not None:
        survey_node_dict['repeatable'] = repeatable
    _css = _create_sub_survey
    sub_survey_data = survey_node_dict.get('sub_surveys', None)
    if sub_survey_data is not None:
        survey_node_dict['sub_surveys'] = [
            _css(session, ssd, node) for ssd in sub_survey_data
        ]
    return construct_survey_node(**survey_node_dict)
Ejemplo n.º 3
0
def _create_answer(session, answer_dict) -> Answer:
    survey_node_id = answer_dict['survey_node_id']
    error = exc.BadRequest('survey_node not found: {}'.format(survey_node_id))
    survey_node = get_model(session, SurveyNode, survey_node_id, error)
    answer_dict['survey_node'] = survey_node
    return construct_answer(**answer_dict)
Ejemplo n.º 4
0
 def _survey(self, survey_id: str) -> Survey:
     return get_model(self.session, Survey, survey_id)