예제 #1
0
 def __init__(self, investigator, request):
     super(USSDBaseView, self).__init__()
     self.investigator = investigator
     self.request = request.dict()
     self.ussd_survey = USSDSurvey(investigator, request)
     self.ussd_register_household = USSDRegisterHousehold(investigator, request)
     self.ussd_report_non_response = USSDReportNonResponse(investigator, request)
     self.is_registering_household = None
     self.is_reporting_non_response = False
     self.set_is_registering_household()
     self.set_is_reporting_non_response()
예제 #2
0
 def __init__(self, interviewer, request):
     super(USSDBaseView, self).__init__()
     self.interviewer = interviewer
     self.request = request.dict()
     self.ussd_survey = USSDSurvey(interviewer, request)
     self.ussd_register_household = USSDRegisterHousehold(interviewer, request)
     self.ussd_report_non_response = USSDReportNonResponse(interviewer, request)
     self.is_registering_household = None
     self.is_reporting_non_response = False
     self.set_is_registering_household()
     self.set_is_reporting_non_response()
예제 #3
0
class USSDBaseView(object):

    ANSWER = {
        'YES': "1",
        'NO': "2",
        "REGISTER_HOUSEHOLD": "1",
        'TAKE_SURVEY': "2",
        'REPORT_NON_RESPONSE': "3",
    }

    def __init__(self, investigator, request):
        super(USSDBaseView, self).__init__()
        self.investigator = investigator
        self.request = request.dict()
        self.ussd_survey = USSDSurvey(investigator, request)
        self.ussd_register_household = USSDRegisterHousehold(investigator, request)
        self.ussd_report_non_response = USSDReportNonResponse(investigator, request)
        self.is_registering_household = None
        self.is_reporting_non_response = False
        self.set_is_registering_household()
        self.set_is_reporting_non_response()

    def set_is_registering_household(self):
        self.is_registering_household = self.investigator.get_from_cache('IS_REGISTERING_HOUSEHOLD')

    def set_is_reporting_non_response(self):
        self.is_reporting_non_response = self.investigator.get_from_cache('IS_REPORTING_NON_RESPONSE')

    def is_new_request(self):
        return self.request['response'] == 'false'

    def response(self):
        answer = self.request['ussdRequestString'].strip()
        if self.investigator.is_blocked:
            return {'action': self.ussd_survey.ACTIONS['END'],
                    'responseString': self.ussd_survey.MESSAGES['INVESTIGATOR_BLOCKED_MESSAGE']}

        if self.is_new_request_parameter(answer) and self.is_new_request():
            action, response_string = self.ussd_survey.render_welcome_or_resume()
            return {'action': action, 'responseString': response_string}

        if self.is_reporting_non_response:
            if self.ussd_report_non_response.can_retake and answer == self.ANSWER['NO']:
                self.ussd_report_non_response.clear_caches()
                self.clear_HH_caches()
                action, response_string = self.render_home_page()
                return {'action': action, 'responseString': response_string}

            if self.ussd_survey.is_resuming_survey and answer == self.ANSWER['NO']:
                action, response_string = self.render_home_page()
                self.clear_HH_caches()
                self.ussd_survey.set_in_session('IS_RESUMING', False)
                return {'action': action, 'responseString': response_string}

            action, response_string = self.ussd_report_non_response.start(answer)
            self.ussd_survey.set_in_session('IS_RESUMING', False)
            return {'action': action, 'responseString': response_string}

        if self.is_registering_household is None:
            if answer == self.ANSWER['TAKE_SURVEY']:
                self.investigator.set_in_cache('IS_REGISTERING_HOUSEHOLD', False)
                action, response_string = self.ussd_survey.start()
                return {'action': action, 'responseString': response_string}

            if answer == self.ANSWER['REGISTER_HOUSEHOLD']:
                self.investigator.set_in_cache('IS_REGISTERING_HOUSEHOLD', True)
                action, response_string = self.ussd_register_household.start("00")
                return {'action': action, 'responseString': response_string}

            if answer == self.ANSWER['REPORT_NON_RESPONSE']:
                self.investigator.set_in_cache('IS_REPORTING_NON_RESPONSE', True)
                action, response_string = self.ussd_report_non_response.start("00")
                return {'action': action, 'responseString': response_string}

            action, response_string = self.ussd_survey.render_welcome_or_resume()
            return {'action': action, 'responseString': response_string}

        if not self.is_registering_household:
            action, response_string = self.ussd_survey.take_survey()
            return {'action': action, 'responseString': response_string}

        if not self.ussd_survey.is_resuming_survey:
            action, response_string = self.ussd_register_household.start(answer)
            self.ussd_survey.set_in_session('IS_RESUMING', False)
            return {'action': action, 'responseString': response_string}

        if answer == USSDSurvey.ANSWER['YES']:
            action, response_string = self.ussd_register_household.start("00")
            self.investigator.set_in_cache('IS_REGISTERING_HOUSEHOLD', True)
            self.ussd_survey.set_in_session('IS_RESUMING', False)
            return {'action': action, 'responseString': response_string}

        action, response_string = self.render_home_page()
        self.clear_HH_caches()
        self.ussd_survey.set_in_session('IS_RESUMING', False)
        return {'action': action, 'responseString': response_string}

    def is_new_request_parameter(self, answer):
        pattern = re.compile(r'\*\d+\#')
        match = re.match(pattern, answer)

        matches_short_code = False

        if HAS_APPLICATION_CODE:
            matches_short_code = (answer == APPLICATION_CODE)

        return not answer or match or matches_short_code

    def render_home_page(self):
        action = self.ussd_survey.ACTIONS['REQUEST']
        response_string = self.ussd_survey.render_menu()
        return action, response_string

    def clear_HH_caches(self):
        self.investigator.clear_interview_caches()
        self.ussd_register_household.set_in_session('HOUSEHOLD', None)
        self.ussd_survey.set_in_session('HOUSEHOLD', None)
예제 #4
0
class USSDBaseView(object):

    ANSWER = {
        'YES': "1",
        'NO': "2",
        "REGISTER_HOUSEHOLD": "1",
        'TAKE_SURVEY': "2",
        'REPORT_NON_RESPONSE': "3",
    }

    def __init__(self, interviewer, request):
        super(USSDBaseView, self).__init__()
        self.interviewer = interviewer
        self.request = request.dict()
        self.ussd_survey = USSDSurvey(interviewer, request)
        self.ussd_register_household = USSDRegisterHousehold(interviewer, request)
        self.ussd_report_non_response = USSDReportNonResponse(interviewer, request)
        self.is_registering_household = None
        self.is_reporting_non_response = False
        self.set_is_registering_household()
        self.set_is_reporting_non_response()

    def set_is_registering_household(self):
        self.is_registering_household = self.interviewer.get_from_cache('IS_REGISTERING_HOUSEHOLD')

    def set_is_reporting_non_response(self):
        self.is_reporting_non_response = self.interviewer.get_from_cache('IS_REPORTING_NON_RESPONSE')

    def is_new_request(self):
        return self.request['response'] == 'false'

    def response(self):
        answer = self.request['ussdRequestString'].strip()
        if self.interviewer.is_blocked:
            return {'action': self.ussd_survey.ACTIONS['END'],
                    'responseString': self.ussd_survey.MESSAGES['Interviewer_BLOCKED_MESSAGE']}

        if self.is_new_request_parameter(answer) and self.is_new_request():
            action, response_string = self.ussd_survey.render_welcome_or_resume()
            return {'action': action, 'responseString': response_string}

        if self.is_reporting_non_response:
            if self.ussd_report_non_response.can_retake and answer == self.ANSWER['NO']:
                self.ussd_report_non_response.clear_caches()
                self.clear_HH_caches()
                action, response_string = self.render_home_page()
                return {'action': action, 'responseString': response_string}

            if self.ussd_survey.is_resuming_survey and answer == self.ANSWER['NO']:
                action, response_string = self.render_home_page()
                self.clear_HH_caches()
                self.ussd_survey.set_in_session('IS_RESUMING', False)
                return {'action': action, 'responseString': response_string}

            action, response_string = self.ussd_report_non_response.start(answer)
            self.ussd_survey.set_in_session('IS_RESUMING', False)
            return {'action': action, 'responseString': response_string}

        if self.is_registering_household is None:
            if answer == self.ANSWER['TAKE_SURVEY']:
                self.interviewer.set_in_cache('IS_REGISTERING_HOUSEHOLD', False)
                action, response_string = self.ussd_survey.start()
                return {'action': action, 'responseString': response_string}

            if answer == self.ANSWER['REGISTER_HOUSEHOLD']:
                self.interviewer.set_in_cache('IS_REGISTERING_HOUSEHOLD', True)
                action, response_string = self.ussd_register_household.start("00")
                return {'action': action, 'responseString': response_string}

            if answer == self.ANSWER['REPORT_NON_RESPONSE']:
                self.interviewer.set_in_cache('IS_REPORTING_NON_RESPONSE', True)
                action, response_string = self.ussd_report_non_response.start("00")
                return {'action': action, 'responseString': response_string}

            action, response_string = self.ussd_survey.render_welcome_or_resume()
            return {'action': action, 'responseString': response_string}

        if not self.is_registering_household:
            action, response_string = self.ussd_survey.take_survey()
            return {'action': action, 'responseString': response_string}

        if not self.ussd_survey.is_resuming_survey:
            action, response_string = self.ussd_register_household.start(answer)
            self.ussd_survey.set_in_session('IS_RESUMING', False)
            return {'action': action, 'responseString': response_string}

        if answer == USSDSurvey.ANSWER['YES']:
            action, response_string = self.ussd_register_household.start("00")
            self.interviewer.set_in_cache('IS_REGISTERING_HOUSEHOLD', True)
            self.ussd_survey.set_in_session('IS_RESUMING', False)
            return {'action': action, 'responseString': response_string}

        action, response_string = self.render_home_page()
        self.clear_HH_caches()
        self.ussd_survey.set_in_session('IS_RESUMING', False)
        return {'action': action, 'responseString': response_string}

    def is_new_request_parameter(self, answer):
        pattern = re.compile(r'\*\d+\#')
        match = re.match(pattern, answer)

        matches_short_code = False

        if HAS_APPLICATION_CODE:
            matches_short_code = (answer == APPLICATION_CODE)

        return not answer or match or matches_short_code

    def render_home_page(self):
        action = self.ussd_survey.ACTIONS['REQUEST']
        response_string = self.ussd_survey.render_menu()
        return action, response_string

    def clear_HH_caches(self):
        self.interviewer.clear_interview_caches()
        self.ussd_register_household.set_in_session('HOUSEHOLD', None)
        self.ussd_survey.set_in_session('HOUSEHOLD', None)
예제 #5
0
class USSDBaseView(object):

    ANSWER = {"YES": "1", "NO": "2", "REGISTER_HOUSEHOLD": "1", "TAKE_SURVEY": "2", "REPORT_NON_RESPONSE": "3"}

    def __init__(self, investigator, request):
        super(USSDBaseView, self).__init__()
        self.investigator = investigator
        self.request = request.dict()
        self.ussd_survey = USSDSurvey(investigator, request)
        self.ussd_register_household = USSDRegisterHousehold(investigator, request)
        self.ussd_report_non_response = USSDReportNonResponse(investigator, request)
        self.is_registering_household = None
        self.is_reporting_non_response = False
        self.set_is_registering_household()
        self.set_is_reporting_non_response()

    def set_is_registering_household(self):
        self.is_registering_household = self.investigator.get_from_cache("IS_REGISTERING_HOUSEHOLD")

    def set_is_reporting_non_response(self):
        self.is_reporting_non_response = self.investigator.get_from_cache("IS_REPORTING_NON_RESPONSE")

    def is_new_request(self):
        return self.request["response"] == "false"

    def response(self):
        answer = self.request["ussdRequestString"].strip()
        if self.investigator.is_blocked:
            return {
                "action": self.ussd_survey.ACTIONS["END"],
                "responseString": self.ussd_survey.MESSAGES["INVESTIGATOR_BLOCKED_MESSAGE"],
            }

        if self.is_new_request_parameter(answer) and self.is_new_request():
            action, response_string = self.ussd_survey.render_welcome_or_resume()
            return {"action": action, "responseString": response_string}

        if self.is_reporting_non_response:
            if self.ussd_report_non_response.can_retake and answer == self.ANSWER["NO"]:
                self.ussd_report_non_response.clear_caches()
                self.clear_HH_caches()
                action, response_string = self.render_home_page()
                return {"action": action, "responseString": response_string}

            if self.ussd_survey.is_resuming_survey and answer == self.ANSWER["NO"]:
                action, response_string = self.render_home_page()
                self.clear_HH_caches()
                self.ussd_survey.set_in_session("IS_RESUMING", False)
                return {"action": action, "responseString": response_string}

            action, response_string = self.ussd_report_non_response.start(answer)
            self.ussd_survey.set_in_session("IS_RESUMING", False)
            return {"action": action, "responseString": response_string}

        if self.is_registering_household is None:
            if answer == self.ANSWER["TAKE_SURVEY"]:
                self.investigator.set_in_cache("IS_REGISTERING_HOUSEHOLD", False)
                action, response_string = self.ussd_survey.start()
                return {"action": action, "responseString": response_string}

            if answer == self.ANSWER["REGISTER_HOUSEHOLD"]:
                self.investigator.set_in_cache("IS_REGISTERING_HOUSEHOLD", True)
                action, response_string = self.ussd_register_household.start("00")
                return {"action": action, "responseString": response_string}

            if answer == self.ANSWER["REPORT_NON_RESPONSE"]:
                self.investigator.set_in_cache("IS_REPORTING_NON_RESPONSE", True)
                action, response_string = self.ussd_report_non_response.start("00")
                return {"action": action, "responseString": response_string}

            action, response_string = self.ussd_survey.render_welcome_or_resume()
            return {"action": action, "responseString": response_string}

        if not self.is_registering_household:
            action, response_string = self.ussd_survey.take_survey()
            return {"action": action, "responseString": response_string}

        if not self.ussd_survey.is_resuming_survey:
            action, response_string = self.ussd_register_household.start(answer)
            self.ussd_survey.set_in_session("IS_RESUMING", False)
            return {"action": action, "responseString": response_string}

        if answer == USSDSurvey.ANSWER["YES"]:
            action, response_string = self.ussd_register_household.start("00")
            self.investigator.set_in_cache("IS_REGISTERING_HOUSEHOLD", True)
            self.ussd_survey.set_in_session("IS_RESUMING", False)
            return {"action": action, "responseString": response_string}

        action, response_string = self.render_home_page()
        self.clear_HH_caches()
        self.ussd_survey.set_in_session("IS_RESUMING", False)
        return {"action": action, "responseString": response_string}

    def is_new_request_parameter(self, answer):
        pattern = re.compile(r"\*\d+\#")
        match = re.match(pattern, answer)

        matches_short_code = False

        if HAS_APPLICATION_CODE:
            matches_short_code = answer == APPLICATION_CODE

        return not answer or match or matches_short_code

    def render_home_page(self):
        action = self.ussd_survey.ACTIONS["REQUEST"]
        response_string = self.ussd_survey.render_menu()
        return action, response_string

    def clear_HH_caches(self):
        self.investigator.clear_interview_caches()
        self.ussd_register_household.set_in_session("HOUSEHOLD", None)
        self.ussd_survey.set_in_session("HOUSEHOLD", None)