示例#1
0
def view_survey_details(short_name):
    survey_details = survey_controllers.get_survey(short_name)
    form = EditSurveyDetailsForm(form=request.form)

    return render_template('edit-survey-details.html', form=form, short_name=short_name,
                           legal_basis=survey_details['legalBasis'],
                           long_name=survey_details['longName'],
                           survey_ref=survey_details['surveyRef'])
示例#2
0
def get_create_collection_exercise_form(survey_ref, short_name):
    logger.info("Retrieving survey data for form",
                short_name=short_name,
                survey_ref=survey_ref)
    form = CreateCollectionExerciseDetailsForm(form=request.form)
    survey_details = survey_controllers.get_survey(short_name)
    return render_template('create-collection-exercise.html',
                           form=form,
                           short_name=short_name,
                           survey_ref=survey_ref,
                           survey_id=survey_details['id'],
                           survey_name=survey_details['shortName'])
示例#3
0
def view_survey_details(short_name):
    survey_details = survey_controllers.get_survey(short_name)
    form = EditSurveyDetailsForm(form=request.form)

    return render_template(
        "edit-survey-details.html",
        form=form,
        short_name=short_name,
        legal_basis=survey_details["legalBasis"],
        long_name=survey_details["longName"],
        survey_ref=survey_details["surveyRef"],
        survey_mode=survey_details["surveyMode"],
    )
def get_create_collection_exercise_form(survey_ref, short_name):
    logger.info("Retrieving survey data for form", short_name=short_name, survey_ref=survey_ref)
    form = CreateCollectionExerciseDetailsForm(form=request.form)
    survey_details = survey_controllers.get_survey(short_name)
    survey_eq_version = survey_details["eqVersion"] if survey_details["surveyMode"] != "SEFT" else ""
    return render_template(
        "create-collection-exercise.html",
        form=form,
        short_name=short_name,
        survey_ref=survey_ref,
        survey_id=survey_details["id"],
        survey_name=survey_details["shortName"],
        survey_eq_version=survey_eq_version,
    )
示例#5
0
def edit_survey_details(short_name):
    form = EditSurveyDetailsForm(form=request.form)
    if not form.validate():
        survey_details = survey_controllers.get_survey(short_name)
        return render_template('edit-survey-details.html', form=form, short_name=short_name, errors=form.errors,
                               legal_basis=survey_details['legalBasis'],
                               long_name=survey_details['longName'],
                               survey_ref=survey_details['surveyRef'],
                               survey_details=survey_details)

    else:
        form = request.form
        survey_controllers.update_survey_details(form.get('hidden_survey_ref'),
                                                 form.get('short_name'),
                                                 form.get('long_name'))
        return redirect(url_for('surveys_bp.view_surveys', short_name=short_name, message_key='survey_changed'))
示例#6
0
def view_survey(short_name):

    survey = survey_controllers.get_survey(short_name)
    breadcrumbs = [
        {
            "text": "Surveys",
            "url": "/surveys"
        },
        {
            "text": f"{survey['surveyRef']} {survey['shortName']}",
        },
    ]

    collection_exercises = (
        collection_exercise_controllers.
        get_collection_exercises_with_events_and_samples_by_survey_id(
            survey["id"]))

    updated_ce_message = None
    if request.args.get("ce_updated"):
        updated_ce_message = "Collection exercise details updated"

    created_ce_message = None
    if request.args.get("ce_created"):
        created_ce_message = "Collection exercise created"

    newly_created_period = request.args.get("new_period")

    # Mapping backend states to frontend sates for the user
    for collex in collection_exercises:
        collex["state"] = map_collection_exercise_state(collex["state"])
        collex["events"] = convert_events_to_new_format(
            collex["events"]) if collex.get("events") else {}

    _sort_collection_exercise(collection_exercises)

    return render_template(
        "survey.html",
        survey=survey,
        collection_exercises=collection_exercises,
        breadcrumbs=breadcrumbs,
        updated_ce_message=updated_ce_message,
        created_ce_message=created_ce_message,
        newly_created_period=newly_created_period,
    )
def view_collection_exercise_details(short_name, period):
    logger.info("Retrieving collection exercise data for form", short_name=short_name, period=period)
    ce_details = build_collection_exercise_details(short_name, period)
    form = EditCollectionExerciseDetailsForm(form=request.form)
    survey_details = survey_controllers.get_survey(short_name)
    ce_state = ce_details["collection_exercise"]["state"]
    locked = ce_state in ("LIVE", "READY_FOR_LIVE", "EXECUTION_STARTED", "VALIDATED", "EXECUTED", "ENDED")

    return render_template(
        "edit-collection-exercise-details.html",
        survey_ref=ce_details["survey"]["surveyRef"],
        form=form,
        short_name=short_name,
        period=period,
        locked=locked,
        ce_state=ce_details["collection_exercise"]["state"],
        user_description=ce_details["collection_exercise"]["userDescription"],
        collection_exercise_id=ce_details["collection_exercise"]["id"],
        survey_id=survey_details["id"],
    )
def get_create_collection_event_form(short_name, period, ce_id, tag):
    logger.info(
        "Retrieving form for create collection exercise event",
        short_name=short_name,
        period=period,
        ce_id=ce_id,
        tag=tag,
    )
    survey = survey_controllers.get_survey(short_name)
    exercises = collection_exercise_controllers.get_collection_exercises_by_survey(survey["id"])
    exercise = get_collection_exercise_by_period(exercises, period)
    if not exercise:
        logger.error("Failed to find collection exercise by period", short_name=short_name, period=period)
        abort(404)

    events = collection_exercise_controllers.get_collection_exercise_events_by_id(exercise["id"])
    form = EventDateForm()
    event_name = get_event_name(tag)
    formatted_events = convert_events_to_new_format(events)
    date_restriction_text = get_date_restriction_text(tag, formatted_events)

    logger.info(
        "Successfully retrieved form for create collection exercise event",
        short_name=short_name,
        period=period,
        ce_id=ce_id,
        tag=tag,
    )

    return render_template(
        "create-ce-event.html",
        ce_id=ce_id,
        short_name=short_name,
        period=period,
        survey=survey,
        event_name=event_name,
        date_restriction_text=date_restriction_text,
        tag=tag,
        form=form,
    )
示例#9
0
def edit_survey_details(short_name):
    form = EditSurveyDetailsForm(form=request.form)
    if not form.validate():
        survey_details = survey_controllers.get_survey(short_name)
        return render_template(
            "edit-survey-details.html",
            form=form,
            short_name=short_name,
            errors=form.errors,
            legal_basis=survey_details["legalBasis"],
            long_name=survey_details["longName"],
            survey_ref=survey_details["surveyRef"],
            survey_details=survey_details,
        )

    else:
        form = request.form
        survey_controllers.update_survey_details(form.get("hidden_survey_ref"),
                                                 form.get("short_name"),
                                                 form.get("long_name"))
        return redirect(
            url_for("surveys_bp.view_surveys", message_key="survey_changed"))
示例#10
0
def view_collection_exercise_details(short_name, period):
    logger.info("Retrieving collection exercise data for form",
                short_name=short_name,
                period=period)
    ce_details = build_collection_exercise_details(short_name, period)
    form = EditCollectionExerciseDetailsForm(form=request.form)
    survey_details = survey_controllers.get_survey(short_name)
    ce_state = ce_details['collection_exercise']['state']
    locked = ce_state in ('LIVE', 'READY_FOR_LIVE', 'EXECUTION_STARTED',
                          'VALIDATED', 'EXECUTED')

    return render_template(
        'edit-collection-exercise-details.html',
        survey_ref=ce_details['survey']['surveyRef'],
        form=form,
        short_name=short_name,
        period=period,
        locked=locked,
        ce_state=ce_details['collection_exercise']['state'],
        user_description=ce_details['collection_exercise']['userDescription'],
        collection_exercise_id=ce_details['collection_exercise']['id'],
        survey_id=survey_details['id'])