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 test_get_ce_events_by_id_no_events(self): with responses.RequestsMock() as rsps: rsps.add(rsps.GET, ce_events_by_id_url, json=[], status=200, content_type='applicaton/json') with self.app.app_context(): collection_exercise = collection_exercise_controllers.get_collection_exercise_events_by_id(ce_id) self.assertEqual(len(collection_exercise), 0, 'Unexpected collection exercise event returned.')
def test_get_ce_events_by_id_all_events(self): with responses.RequestsMock() as rsps: rsps.add(rsps.GET, ce_events_by_id_url, json=ce_events, status=200, content_type='applicaton/json') with self.app.app_context(): collection_exercise = collection_exercise_controllers.get_collection_exercise_events_by_id(ce_id) self.assertIn('mps', collection_exercise[0]['tag'], 'MPS not in collection exercise events') self.assertIn('go_live', collection_exercise[1]['tag'], 'Go live not in collection exercise events') self.assertIn('return_by', collection_exercise[2]['tag'], 'Return by not in collection exercise events') self.assertIn('exercise_end', collection_exercise[3]['tag'], 'Exercise end not in collection exercise events')
def test_get_ce_events_by_id_all_events(self): with responses.RequestsMock() as rsps: rsps.add(rsps.GET, ce_events_by_id_url, json=ce_events, status=200, content_type="applicaton/json") with self.app.app_context(): collection_exercise = collection_exercise_controllers.get_collection_exercise_events_by_id(ce_id) self.assertIn("mps", collection_exercise[0]["tag"], "MPS not in collection exercise events") self.assertIn("go_live", collection_exercise[1]["tag"], "Go live not in collection exercise events") self.assertIn("return_by", collection_exercise[2]["tag"], "Return by not in collection exercise events") self.assertIn( "exercise_end", collection_exercise[3]["tag"], "Exercise end not in collection exercise events" )
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, )