def db_update_step(session, tid, step_id, request, language): """ Transaction for updating a step :param session: An ORM session :param tid: The tenant ID :param step_id: the step_id of the step to update :param request: the step definition dict :param language: the language of the step definition dict :return: a serialization of the object """ step = models.db_get( session, models.Step, models.Step.id == step_id, models.Questionnaire.id == models.Step.questionnaire_id, models.Questionnaire.tid == tid) fill_localized_keys(request, models.Step.localized_keys, language) step.update(request) for child in request['children']: db_update_field(session, tid, child['id'], child, language) db_reset_option_triggers(session, 'step', step.id) for trigger in request.get('triggered_by_options', []): db_create_option_trigger(session, trigger['option'], 'step', step.id, trigger.get('sufficient', True)) return serialize_step(session, tid, step, language)
def db_create_step(session, tid, request, language): """ Transaction for creating a step :param session: An ORM session :param tid: A tenant ID :param request: The request data :param session: the session on which perform queries. :param language: the language of the specified steps. """ fill_localized_keys(request, models.Step.localized_keys, language) step = db_add(session, models.Step, request) for trigger in request.get('triggered_by_options', []): db_create_option_trigger(session, trigger['option'], 'step', step.id, trigger.get('sufficient', True)) for c in request['children']: c['tid'] = tid c['step_id'] = step.id db_create_field(session, tid, c, language) return serialize_step(session, tid, step, language)