def build_collection_exercise_details(short_name, period): survey = survey_controllers.get_survey_by_shortname(short_name) survey_id = survey["id"] 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) collection_exercise_id = exercise["id"] survey["shortName"] = format_short_name(survey["shortName"]) full_exercise = collection_exercise_controllers.get_collection_exercise_by_id(collection_exercise_id) exercise_events = collection_exercise_controllers.get_collection_exercise_events_by_id(collection_exercise_id) collection_instruments = collection_instrument_controllers.get_collection_instruments_by_classifier( collection_exercise_id=collection_exercise_id, survey_id=survey_id ) eq_ci_selectors = collection_instrument_controllers.get_collection_instruments_by_classifier( ci_type="EQ", survey_id=survey_id ) summary_id = collection_exercise_controllers.get_linked_sample_summary_id(collection_exercise_id) sample_summary = sample_controllers.get_sample_summary(summary_id) if summary_id else None ci_classifiers = survey_controllers.get_survey_ci_classifier(survey_id) return { "survey": survey, "collection_exercise": full_exercise, "events": convert_events_to_new_format(exercise_events), "collection_instruments": collection_instruments, "eq_ci_selectors": eq_ci_selectors, "sample_summary": _format_sample_summary(sample_summary), "ci_classifiers": ci_classifiers, }
def update_event_date(short_name, period, tag): survey = survey_controllers.get_survey_by_shortname(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']) event_name = get_event_name(tag) formatted_events = convert_events_to_new_format(events) date_restriction_text = get_date_restriction_text(tag, formatted_events) try: event = formatted_events[tag] form = EventDateForm(day=event['date'][:2], month=event['month'], year=event['date'][-4:], hour=event['time'][:2], minute=event['time'][3:5]) except KeyError: form = EventDateForm() return render_template('update-event-date.html', form=form, ce=exercise, period=period, survey=survey, event_name=event_name, date_restriction_text=date_restriction_text)
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 update_event_date(short_name, period, tag): survey = survey_controllers.get_survey_by_shortname(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"]) show = is_viewed_reminder_last_in_sequence(events, tag) event_name = get_event_name(tag) formatted_events = convert_events_to_new_format(events) date_restriction_text = get_date_restriction_text(tag, formatted_events) try: event = formatted_events[tag] form = EventDateForm( day=event["date"][:2], month=event["month"], year=event["date"][-4:], hour=event["time"][:2], minute=event["time"][3:5], ) except KeyError: form = EventDateForm() return render_template( "update-event-date.html", form=form, ce=exercise, period=period, survey=survey, event_name=event_name, date_restriction_text=date_restriction_text, show=show, tag=tag, )
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, )