Exemple #1
0
def admin_serialize_context(store, context, language):
    """
    Serialize the specified context

    :param store: the store on which perform queries.
    :param language: the language in which to localize data.
    :return: a dictionary representing the serialization of the context.
    """
    ret_dict = {
        'id': context.id,
        'receivers': [r.id for r in context.receivers],
        'tip_timetolive': context.tip_timetolive / (60 * 60 * 24),
        'select_all_receivers': context.select_all_receivers,
        'maximum_selectable_receivers': context.maximum_selectable_receivers,
        'show_context': context.show_context,
        'show_recipients_details': context.show_recipients_details,
        'allow_recipients_selection': context.allow_recipients_selection,
        'show_small_cards': context.show_small_cards,
        'enable_comments': context.enable_comments,
        'enable_messages': context.enable_messages,
        'enable_two_way_comments': context.enable_two_way_comments,
        'enable_two_way_messages': context.enable_two_way_messages,
        'enable_attachments': context.enable_attachments,
        'presentation_order': context.presentation_order,
        'show_receivers_in_alphabetical_order': context.show_receivers_in_alphabetical_order,
        'questionnaire_layout': context.questionnaire_layout,
        'reset_questionnaire': False,
        'steps': [serialize_step(store, s, language) for s in context.steps]
    }

    return get_localized_values(ret_dict, context, context.localized_keys, language)
Exemple #2
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.steps]
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]
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]
Exemple #5
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)
Exemple #6
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)
Exemple #7
0
def update_step(store, step_id, request, language):
    return serialize_step(store, db_update_step(store, step_id, request, language), language)
Exemple #8
0
def create_step(store, step, language):
    """
    Transaction that perform db_create_step
    """
    return serialize_step(store, db_create_step(store, step, language), language)
Exemple #9
0
def update_step(store, step_id, request, language):
    return serialize_step(store,
                          db_update_step(store, step_id, request, language),
                          language)
Exemple #10
0
def create_step(store, step, language):
    """
    Transaction that perform db_create_step
    """
    return serialize_step(store, db_create_step(store, step, language),
                          language)