Beispiel #1
0
def _submit_data(user):

    answer_store = get_answer_store(user)

    if answer_store.answers:
        metadata = get_metadata(user)
        collection_metadata = get_collection_metadata(user)
        schema = load_schema_from_metadata(metadata)
        completed_blocks = get_completed_blocks(user)
        routing_path = PathFinder(schema, answer_store, metadata,
                                  completed_blocks).get_full_routing_path()

        message = convert_answers(metadata,
                                  collection_metadata,
                                  schema,
                                  answer_store,
                                  routing_path,
                                  flushed=True)
        encrypted_message = encrypt(message, current_app.eq['key_store'],
                                    KEY_PURPOSE_SUBMISSION)

        sent = current_app.eq['submitter'].send_message(
            encrypted_message, current_app.config['EQ_RABBITMQ_QUEUE_NAME'],
            metadata['tx_id'])

        if not sent:
            raise SubmissionFailedException()

        get_questionnaire_store(user.user_id, user.user_ik).delete()
        return True

    return False
Beispiel #2
0
def dump_submission():
    answer_store = get_answer_store(current_user)
    metadata = get_metadata(current_user)
    collection_metadata = get_collection_metadata(current_user)
    session_data = get_session_store().session_data
    schema = load_schema_from_session_data(session_data)
    completed_blocks = get_completed_blocks(current_user)
    routing_path = PathFinder(schema, answer_store, metadata,
                              completed_blocks).get_full_routing_path()
    response = {
        'submission':
        convert_answers(metadata, collection_metadata, schema, answer_store,
                        routing_path)
    }
    return jsonify(response), 200
Beispiel #3
0
def submit_answers(routing_path, eq_id, form_type, schema):
    metadata = get_metadata(current_user)
    collection_metadata = get_collection_metadata(current_user)
    answer_store = get_answer_store(current_user)

    message = json.dumps(
        convert_answers(
            metadata,
            collection_metadata,
            schema,
            answer_store,
            routing_path,
        ))

    encrypted_message = encrypt(message, current_app.eq['key_store'],
                                KEY_PURPOSE_SUBMISSION)
    sent = current_app.eq['submitter'].send_message(
        encrypted_message,
        current_app.config['EQ_RABBITMQ_QUEUE_NAME'],
        metadata['tx_id'],
    )
    if current_app.config['EQ_PUBSUB_ENABLED']:
        current_app.eq['pubsub_submitter'].send_message(
            encrypted_message,
            current_app.config['EQ_PUBSUB_TOPIC_ID'],
            metadata['tx_id'],
        )

    if not sent:
        raise SubmissionFailedException()

    submitted_time = datetime.utcnow()

    _store_submitted_time_in_session(submitted_time)

    if is_view_submitted_response_enabled(schema.json):
        _store_viewable_submission(list(answer_store), metadata,
                                   submitted_time)

    get_questionnaire_store(current_user.user_id,
                            current_user.user_ik).delete()

    return redirect(
        url_for('post_submission.get_thank_you',
                eq_id=eq_id,
                form_type=form_type))
Beispiel #4
0
def _get_context(full_routing_path,
                 block,
                 current_location,
                 schema,
                 form=None):
    metadata = get_metadata(current_user)
    collection_metadata = get_collection_metadata(current_user)

    answer_store = get_answer_store(current_user)
    schema_context = _get_schema_context(full_routing_path, current_location,
                                         metadata, collection_metadata,
                                         answer_store, schema)
    rendered_block = renderer.render(block, **schema_context)

    return build_view_context(block['type'],
                              metadata,
                              schema,
                              answer_store,
                              schema_context,
                              rendered_block,
                              current_location,
                              form=form)
 def other_wrapped_function(*args, **kwargs):
     collection_metadata = get_collection_metadata(current_user)
     return function(collection_metadata, *args, **kwargs)