コード例 #1
0
 def handle_ussd_input(self, ussd_input):
     # check if input is for previous or next page
     if self.ussd_request.input.strip() in ("98", "00"):
         page = self.paginator.page(
             self.ussd_request.session['_ussd_state']['page']
         )
         if self.ussd_request.input.strip() == "98" and page.has_next():
             new_page_number = page.next_page_number()
             self.ussd_request.session['_ussd_state']['page'] = \
                 new_page_number
             return UssdResponse(self._render_django_page(new_page_number))
         # Restart page object from begining
         if self.ussd_request.input.strip() == "98" and page.has_next() == False:
             new_page_number = 1
             self.ussd_request.session['_ussd_state']['page'] = \
                 new_page_number
             return UssdResponse(self._render_django_page(new_page_number))
         elif self.ussd_request.input.strip() == '00' and \
                 page.has_previous():
             new_page_number = page.previous_page_number()
             self.ussd_request.session['_ussd_state']['page'] = \
                 new_page_number
             return UssdResponse(self._render_django_page(new_page_number))
     next_screen = self.evaluate_input()
     if next_screen:
         return self.route_options(next_screen)
     return self.handle_invalid_input()
コード例 #2
0
ファイル: input_screen.py プロジェクト: owezzy/ussd_airflow
    def handle(self):
        if not self.ussd_request.input:
            response_text = self.get_text()
            ussd_screen = dict(name=self.handler,
                               start=datetime.datetime.now(),
                               screen_text=response_text)
            self.ussd_request.session['steps'].append(ussd_screen)

            return UssdResponse(response_text)
        else:
            # validate input
            validation_rules = self.screen_content.get("validators", {})
            for validation_rule in validation_rules:

                if 'regex' in validation_rule:
                    regex_expression = validation_rule['regex']
                    regex = re.compile(regex_expression)
                    is_valid = bool(
                        regex.search(force_text(self.ussd_request.input)))
                else:
                    is_valid = self.evaluate_jija_expression(
                        validation_rule['expression'])

                # show error message if validation failed
                if not is_valid:
                    return UssdResponse(self.get_text(validation_rule['text']))

            session_key = self.screen_content['input_identifier']
            next_handler = self.screen_content['next_screen']
            self.ussd_request.session[session_key] = \
                self.ussd_request.input

            self.ussd_request.session['steps'][-1].update(
                end=datetime.datetime.now(), selection=self.ussd_request.input)
            return self.ussd_request.forward(next_handler)
コード例 #3
0
    def handle(self):
        if not self.ussd_request.input:
            return UssdResponse(self.get_text())
        else:
            # validate input
            validation_rules = self.screen_content.get("validators", {})
            for validation_rule in validation_rules:

                if 'regex' in validation_rule:
                    regex_expression = validation_rule['regex']
                    regex = re.compile(regex_expression)
                    is_valid = bool(
                        regex.search(force_text(self.ussd_request.input)))
                else:
                    is_valid = self.evaluate_jija_expression(
                        validation_rule['expression'])

                # show error message if validation failed
                if not is_valid:
                    return UssdResponse(self.get_text(validation_rule['text']))

            session_key = self.screen_content['input_identifier']
            next_handler = self.screen_content['next_screen']
            self.ussd_request.session[session_key] = \
                self.ussd_request.input

            return self.ussd_request.forward(next_handler)
コード例 #4
0
 def finalize_response(self, response):
     if isinstance(response, UssdRequest):
         self.logger = get_logger(__name__).bind(**response.all_variables())
         try:
             ussd_response = self.ussd_dispatcher(response)
         except Exception as e:
             ussd_response = UssdResponse(str(e))
         return self.ussd_response_handler(ussd_response)
     return response
コード例 #5
0
    def handle(self):

        if not self.ussd_request.input:
            return UssdResponse(self.ussd_text)

        else:
            next_screen = self.evaluate_input()
            if next_screen:
                return self.ussd_request.forward(next_screen)
            return self.handle_invalid_input()
コード例 #6
0
    def handle(self):

        ussd_text = self._add_end_line(self.get_text()) + \
                    self.display_options(self.list_options) + \
                    self.display_options(
                        self.menu_options,
                        start_index=len(self.list_options) + 1
                    )

        if not self.ussd_request.input:
            return UssdResponse(ussd_text)

        else:
            next_screen = self.evaluate_input()
            if next_screen:
                return self.ussd_request.forward(next_screen)
            return UssdResponse(
                self._add_end_line(self.get_text(self.error_message)) +
                ussd_text)
コード例 #7
0
    def handle(self):
        # set session has expired
        self.ussd_request.session[ussd_airflow_variables.expiry] = True

        if self.initial_screen.get('ussd_report_session'):
            # schedule a task to report session
            self.fire_ussd_report_session_task(self.initial_screen,
                                               self.ussd_request.session_id)

        return UssdResponse(self.get_text(), status=False)
コード例 #8
0
ファイル: quit_screen.py プロジェクト: wekesa/ussd_engine
    def handle(self):
        # set session has expired
        self.ussd_request.session.set_expiry(-1)

        if self.initial_screen.get('ussd_report_session'):
            # schedule a task to report session
            self.fire_ussd_report_session_task(self.initial_screen,
                                               self.ussd_request.session_id,
                                               support_countdown=False)

        return UssdResponse(self.get_text(), status=False)
コード例 #9
0
 def handle_ussd_input(self, ussd_input):
     # check if input is for previous or next page
     if self.ussd_request.input.strip() in (self.pagination_more_option_value,
                                            self.pagination_back_option_value):
         page = self.paginator.page(
             self.ussd_request.session['_ussd_state']['page']
         )
         if self.ussd_request.input.strip() == self.pagination_more_option_value and page.has_next():
             new_page_number = page.next_page_number()
             self.ussd_request.session['_ussd_state']['page'] = \
                 new_page_number
             return UssdResponse(self._render_django_page(new_page_number))
         elif self.ussd_request.input.strip() == self.pagination_back_option_value and \
                 page.has_previous():
             new_page_number = page.previous_page_number()
             self.ussd_request.session['_ussd_state']['page'] = \
                 new_page_number
             return UssdResponse(self._render_django_page(new_page_number))
     next_screen = self.evaluate_input()
     if next_screen:
         return self.route_options(next_screen)
     return self.handle_invalid_input()
コード例 #10
0
    def handle_invalid_input(self):
        # validate input
        validation_rules = self.screen_content.get("validators", {})
        for validation_rule in validation_rules:

            if 'regex' in validation_rule:
                regex_expression = validation_rule['regex']
                regex = re.compile(regex_expression)
                is_valid = bool(
                    regex.search(force_str(self.ussd_request.input)))
            else:
                is_valid = self.evaluate_jija_expression(
                    validation_rule['expression'],
                    session=self.ussd_request.session)

            # show error message if validation failed
            if not is_valid:
                return UssdResponse(self.get_text(validation_rule['text']))

        self.ussd_request.session[
            self.screen_content['input_identifier']] = self.ussd_request.input

        return self.route_options()
コード例 #11
0
 def handle(self):
     self.ussd_request.session[ussd_airflow_variables.expiry] = True
     return UssdResponse(self.get_text(), status=False)
コード例 #12
0
 def handle_invalid_input(self):
     return UssdResponse(
         self._add_end_line(self.get_text(self.error_message)) +
         self.ussd_text)
コード例 #13
0
 def handle_invalid_input(self):
     return UssdResponse(
         self._add_end_line(
             self.get_text(self.error_message)) +
         self._render_django_page(1)
     )
コード例 #14
0
 def show_ussd_content():  # This method doesn't have to be static
     # Do anything custom here.
     return UssdResponse("This is a custom Handler1")
コード例 #15
0
 def handle(self):
     return UssdResponse(self.get_text(), status=False)