From e423368e64c5c1e4c641cf34f59c00b14ff418d1 Mon Sep 17 00:00:00 2001 From: Hlamalani Date: Tue, 1 Aug 2023 09:08:44 +0200 Subject: [PATCH] move survey validation --- yal/main.py | 13 ++----------- yal/surveys/endline.py | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/yal/main.py b/yal/main.py index e3aa5cfc..e6bdb9b8 100644 --- a/yal/main.py +++ b/yal/main.py @@ -2,7 +2,7 @@ import logging from vaccine.models import Message -from vaccine.states import Choice, EndState, FreeText, WhatsAppButtonState +from vaccine.states import Choice, EndState, WhatsAppButtonState from vaccine.utils import get_display_choices, random_id from yal import rapidpro, utils from yal.askaquestion import Application as AaqApplication @@ -25,7 +25,6 @@ from yal.utils import ( get_current_datetime, get_generic_error, - get_generic_error_options, is_integer, normalise_phonenumber, replace_persona_fields, @@ -231,7 +230,7 @@ async def process_message(self, message): if endline_survey_started and not self.state_name: self.user.session_id = None - self.state_name = "state_survey_validation" + self.state_name = EndlineSurveyApplication.SURVEY_VALIDATION_STATE # Fields that RapidPro sets after a feedback push message feedback_state = await self.get_feedback_state() @@ -861,11 +860,3 @@ async def publish_message(self, question): """ content = replace_persona_fields(question, self.user.metadata) await self.worker.publish_message(self.inbound.reply(content)) - - async def state_survey_validation(self): - """ - Validates survey keywords from RapidPro - """ - random_error = get_generic_error_options() - - return FreeText(self, question=random_error, next=None) diff --git a/yal/surveys/endline.py b/yal/surveys/endline.py index ec511b0e..0a02ed48 100644 --- a/yal/surveys/endline.py +++ b/yal/surveys/endline.py @@ -2,12 +2,17 @@ import logging from vaccine.base_application import BaseApplication -from vaccine.states import Choice, WhatsAppButtonState +from vaccine.states import Choice, FreeText, WhatsAppButtonState from yal import rapidpro from yal.askaquestion import Application as AAQApplication from yal.assessments import Application as AssessmentApplication from yal.change_preferences import Application as ChangePreferencesApplication -from yal.utils import get_current_datetime, get_generic_error, normalise_phonenumber +from yal.utils import ( + get_current_datetime, + get_generic_error, + get_generic_error_options, + normalise_phonenumber, +) logger = logging.getLogger(__name__) @@ -16,6 +21,7 @@ class Application(BaseApplication): depression_score = 0 anxiety_score = 0 START_STATE = "state_endline_start" + SURVEY_VALIDATION_STATE = "state_survey_validation" async def set_endline_reminder_timer(self): msisdn = normalise_phonenumber(self.inbound.from_addr) @@ -468,3 +474,11 @@ async def state_endline_end(self): }, error=self._(get_generic_error()), ) + + async def state_survey_validation(self): + """ + Validates survey keywords from RapidPro + """ + random_error = get_generic_error_options() + + return FreeText(self, question=random_error, next=None)