Exemplo n.º 1
0
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)
Exemplo n.º 2
0
def create_step(session, tid, step, language):
    """
    Transaction that perform db_create_step
    """
    return serialize_step(session, tid,
                          db_create_step(session, tid, step, language),
                          language)
Exemplo n.º 3
0
def db_get_questionnaire_steps(store, questionnaire_id, language):
    """
    Returns:
        (dict) the questionnaire associated with the questionnaire with the specified id.
    """
    questionnaire = store.find(models.Questionnaire, models.Questionnaire.id == questionnaire_id).one()

    if not questionnaire:
        log.err("Requested invalid questionnaire")
        raise errors.QuestionnaireIdNotFound

    return [serialize_step(store, s, language) for s in questionnaire.steps]
Exemplo n.º 4
0
def db_get_context_steps(store, context_id, language):
    """
    Returns:
        (dict) the questionnaire associated with the context with the specified id.
    """
    context = store.find(models.Context, models.Context.id == context_id).one()

    if not context:
        log.err("Requested invalid context")
        raise errors.ContextIdNotFound

    return [serialize_step(store, s, language) for s in context.questionnaire.steps]
Exemplo n.º 5
0
def db_get_context_steps(store, context_id, language):
    """
    Returns:
        (dict) the questionnaire associated with the context with the specified id.
    """
    context = store.find(models.Context, models.Context.id == context_id).one()

    if not context:
        log.err("Requested invalid context")
        raise errors.ContextIdNotFound

    return [serialize_step(store, s, language) for s in context.questionnaire.steps]
Exemplo n.º 6
0
def db_get_questionnaire_steps(store, questionnaire_id, language):
    """
    Returns:
        (dict) the questionnaire associated with the questionnaire with the specified id.
    """
    questionnaire = store.find(
        models.Questionnaire,
        models.Questionnaire.id == questionnaire_id).one()

    if not questionnaire:
        log.err("Requested invalid questionnaire")
        raise errors.QuestionnaireIdNotFound

    return [serialize_step(store, s, language) for s in questionnaire.steps]
Exemplo n.º 7
0
def get_step(store, step_id, language):
    """
    Serialize the specified step

    :param store: the store on which perform queries.
    :param step_id: the id corresponding to the step.
    :param language: the language in which to localize data
    :return: the currently configured step.
    :rtype: dict
    """
    step = store.find(models.Step, models.Step.id == step_id).one()
    if not step:
        raise errors.StepIdNotFound

    return serialize_step(store, step, language)
Exemplo n.º 8
0
def get_step(store, step_id, language):
    """
    Serialize the specified step

    :param store: the store on which perform queries.
    :param step_id: the id corresponding to the step.
    :param language: the language in which to localize data
    :return: the currently configured step.
    :rtype: dict
    """
    step = store.find(models.Step, models.Step.id == step_id).one()
    if not step:
        raise errors.StepIdNotFound

    return serialize_step(store, step, language)
Exemplo n.º 9
0
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)
Exemplo n.º 10
0
def update_step(session, tid, step_id, request, language):
    return serialize_step(
        session, tid, db_update_step(session, tid, step_id, request, language),
        language)
Exemplo n.º 11
0
def update_step(store, step_id, request, language):
    return serialize_step(store,
                          db_update_step(store, step_id, request, language),
                          language)
Exemplo n.º 12
0
def update_step(session, tid, step_id, request, language):
    return serialize_step(session, tid, db_update_step(session, tid, step_id, request, language), language)
Exemplo n.º 13
0
def create_step(session, tid, step, language):
    """
    Transaction that perform db_create_step
    """
    return serialize_step(session, tid, db_create_step(session, tid, step, language), language)
Exemplo n.º 14
0
def update_step(store, step_id, request, language):
    return serialize_step(store, db_update_step(store, step_id, request, language), language)