예제 #1
0
 def test_should_activate_the_language(self):
     mangrove_request = dict()
     form_code = '123'
     PostSMSProcessorLanguageActivator(dbm=None,
                                       request=mangrove_request).process(
                                           form_code, {})
     self.assertEqual(self.language, translation.get_language())
     self.assertEqual(form_code, mangrove_request['form_code'])
예제 #2
0
def submit_to_player(incoming_request):
    try:
        dbm = incoming_request['dbm']
        post_sms_parser_processors = [PostSMSProcessorLanguageActivator(dbm, incoming_request),
                    PostSMSProcessorNumberOfAnswersValidators(dbm, incoming_request)]
        sms_player = SMSPlayer(dbm, LocationBridge(get_location_tree(),get_loc_hierarchy=get_location_hierarchy),
            post_sms_parser_processors=post_sms_parser_processors)
        mangrove_request = Request(message=incoming_request['incoming_message'],
            transportInfo=incoming_request['transport_info'])
        response = sms_player.accept(mangrove_request, logger=incoming_request.get("logger"))
        message = SMSResponse(response).text(dbm)
        send_message(incoming_request, response)
    except DataObjectAlreadyExists as e:
        message = ugettext("%s with %s = %s already exists.") % (ugettext(e.data[2]), ugettext(e.data[0]), e.data[1])
    except Exception as exception:
        message = handle(exception, incoming_request)

    incoming_request['outgoing_message'] = message
    return incoming_request
예제 #3
0
def submit_to_player(incoming_request):
    sent_via_sms_test_questionnaire = incoming_request.get(
        'test_sms_questionnaire', False)
    organization = incoming_request.get('organization')
    organization = organization

    try:
        dbm = incoming_request['dbm']
        post_sms_parser_processors = [
            PostSMSProcessorLanguageActivator(dbm, incoming_request),
            PostSMSProcessorNumberOfAnswersValidators(dbm, incoming_request)
        ]
        sms_player = SMSPlayer(
            dbm,
            LocationBridge(get_location_tree(),
                           get_loc_hierarchy=get_location_hierarchy),
            post_sms_parser_processors=post_sms_parser_processors,
            feeds_dbm=incoming_request['feeds_dbm'])
        mangrove_request = Request(
            message=incoming_request['incoming_message'],
            transportInfo=incoming_request['transport_info'])
        response = sms_player.accept(mangrove_request,
                                     logger=incoming_request.get("logger"))

        if response.is_registration and not sent_via_sms_test_questionnaire:
            organization.increment_message_count_for(sms_registration_count=1)

        if not response.is_registration and sent_via_sms_test_questionnaire:
            organization.increment_message_count_for(incoming_web_count=1)

        mail_feed_errors(response, dbm.database_name)
        message = SMSResponse(response).text(dbm)
        send_message(incoming_request, response)
    except DataObjectAlreadyExists as e:
        message = ugettext("The Unique ID Number %s is already used for the %s %s. Register your %s with a different ID.") % \
                  (e.data[1], e.data[2], e.data[3], e.data[2])
        if not sent_via_sms_test_questionnaire:
            organization.increment_message_count_for(sms_registration_count=1)
    except DataObjectNotFound as exception:
        if sent_via_sms_test_questionnaire:
            organization.increment_message_count_for(incoming_web_count=1)
        message = handle(exception, incoming_request)
    except FormModelDoesNotExistsException as exception:
        if sent_via_sms_test_questionnaire:
            organization.increment_message_count_for(incoming_web_count=1)
        message = handle(exception, incoming_request)
    except Exception as exception:
        message = handle(exception, incoming_request)

    incoming_request['outgoing_message'] = message

    if not sent_via_sms_test_questionnaire:
        SMS(message=message,
            message_id=incoming_request['message_id'],
            organization=incoming_request['organization'],
            msg_from=mangrove_request.transport.source,
            msg_to=mangrove_request.transport.destination,
            msg_type=MSG_TYPE_SUBMISSION_REPLY,
            status="Submitted").save()

    return incoming_request
예제 #4
0
def submit_to_player(incoming_request):
    sent_via_sms_test_questionnaire = incoming_request.get('test_sms_questionnaire', False)
    organization = incoming_request.get('organization')
    organization = organization
    should_increment_incoming_sms_count = True if not sent_via_sms_test_questionnaire else False
    response =None
    try:

        dbm = incoming_request['dbm']
        mangrove_request = Request(message=incoming_request['incoming_message'],
                                   transportInfo=incoming_request['transport_info'])

        post_sms_parser_processors = [PostSMSProcessorLanguageActivator(dbm, incoming_request),
                                      PostSMSProcessorCheckDSIsRegistered(dbm, incoming_request)]
        if organization.in_trial_mode:
            post_sms_parser_processors.append(PostSMSProcessorCheckLimits(dbm, incoming_request))

        post_sms_parser_processors.extend([PostSMSProcessorNumberOfAnswersValidators(dbm, incoming_request),
                                           PostSMSProcessorCheckDSIsLinkedToProject(dbm, incoming_request)])

        sms_player = SMSPlayer(dbm, LocationBridge(get_location_tree(), get_loc_hierarchy=get_location_hierarchy),
                               post_sms_parser_processors=post_sms_parser_processors,
                               feeds_dbm=incoming_request['feeds_dbm'])

        response = sms_player.accept(mangrove_request, logger=incoming_request.get("logger"),
                                     translation_processor=TranslationProcessor)

        if response.is_registration:
            incoming_request['is_registration'] = True
            if not sent_via_sms_test_questionnaire:
                organization.increment_message_count_for(sms_registration_count=1)
        else:
            if sent_via_sms_test_questionnaire:
                organization.increment_message_count_for(incoming_web_count=1)
            check_quotas_and_update_users(organization, sms_channel=True)

        mail_feed_errors(response, dbm.database_name)
        message = SMSResponse(response, incoming_request).text(dbm)
        send_message(incoming_request, response)
    except DataObjectAlreadyExists as e:
        message = identification_number_already_exists_handler(dbm, e.data[1], e.data[2])
        if not sent_via_sms_test_questionnaire:
            organization.increment_message_count_for(sms_registration_count=1)

    except DataObjectNotFound as exception:
        if sent_via_sms_test_questionnaire:
            organization.increment_message_count_for(incoming_web_count=1)
        message = handle(exception, incoming_request)

    except FormModelDoesNotExistsException as exception:
        if sent_via_sms_test_questionnaire:
            organization.increment_message_count_for(incoming_web_count=1)
        message = incorrect_questionnaire_code_handler(dbm, exception.data[0], incoming_request)

    except SMSParserWrongNumberOfAnswersException:
        form_model = sms_player.get_form_model(mangrove_request)
        if not form_model.is_entity_registration_form():
            if sent_via_sms_test_questionnaire:
                organization.increment_message_count_for(incoming_web_count=1)

            message = incorrect_number_of_answers_for_submission_handler(dbm, form_model.form_code, incoming_request)
        elif form_model.is_entity_registration_form():
            message = incorrect_number_of_answers_for_uid_registration_handler(dbm, form_model.form_code, incoming_request)

    except (ExceedSubmissionLimitException, ExceedSMSLimitException) as exception:
        should_increment_incoming_sms_count = False
        message = handle(exception, incoming_request)

    except Exception as exception:
        if sent_via_sms_test_questionnaire:
            organization.increment_message_count_for(incoming_web_count=1)
        message = handle(exception, incoming_request)

    if should_increment_incoming_sms_count:
        organization.increment_incoming_message_count()

    if response and not response.is_registration:
        check_quotas_and_update_users(organization, )
    return post_player_handler(incoming_request, message)
예제 #5
0
def submit_to_player(incoming_request):
    sent_via_sms_test_questionnaire = incoming_request.get(
        'test_sms_questionnaire', False)
    organization = incoming_request.get('organization')
    organization = organization

    try:
        dbm = incoming_request['dbm']
        mangrove_request = Request(
            message=incoming_request['incoming_message'],
            transportInfo=incoming_request['transport_info'])
        response = _is_datasender_registered(dbm, incoming_request)
        if not response:
            post_sms_parser_processors = [
                PostSMSProcessorLanguageActivator(dbm, incoming_request)
            ]
            if organization.in_trial_mode:
                post_sms_parser_processors.append(
                    PostSMSProcessorCheckLimits(dbm, incoming_request))

            post_sms_parser_processors.extend([
                PostSMSProcessorNumberOfAnswersValidators(
                    dbm, incoming_request),
                PostSMSProcessorCheckDSIsLinkedToProject(
                    dbm, incoming_request)
            ])

            sms_player = SMSPlayer(
                dbm,
                LocationBridge(get_location_tree(),
                               get_loc_hierarchy=get_location_hierarchy),
                post_sms_parser_processors=post_sms_parser_processors,
                feeds_dbm=incoming_request['feeds_dbm'])

            response = sms_player.accept(
                mangrove_request,
                logger=incoming_request.get("logger"),
                translation_processor=TranslationProcessor)

            if response.is_registration:
                incoming_request['is_registration'] = True
                if not sent_via_sms_test_questionnaire:
                    organization.increment_message_count_for(
                        sms_registration_count=1)

            if not response.is_registration:
                if sent_via_sms_test_questionnaire:
                    organization.increment_message_count_for(
                        incoming_web_count=1)
                check_quotas_and_update_users(organization, sms_channel=True)

        mail_feed_errors(response, dbm.database_name)
        message = SMSResponse(response, incoming_request).text(dbm)
        send_message(incoming_request, response)
    except DataObjectAlreadyExists as e:
        message = identification_number_already_exists_handler(
            dbm, e.data[1], e.data[2])
        if not sent_via_sms_test_questionnaire:
            organization.increment_message_count_for(sms_registration_count=1)

    except DataObjectNotFound as exception:
        if sent_via_sms_test_questionnaire:
            organization.increment_message_count_for(incoming_web_count=1)
        message = handle(exception, incoming_request)

    except FormModelDoesNotExistsException as exception:
        if sent_via_sms_test_questionnaire:
            organization.increment_message_count_for(incoming_web_count=1)
        message = incorrect_questionnaire_code_handler(dbm, exception.data[0])

    except SMSParserWrongNumberOfAnswersException as exception:
        form_model = sms_player.get_form_model(mangrove_request)
        if not form_model.is_entity_registration_form():
            organization.increment_message_count_for(
                incoming_web_count=1
            ) if sent_via_sms_test_questionnaire else organization.increment_message_count_for(
                incoming_sms_count=1)
            message = incorrect_number_of_answers_for_submission_handler(
                dbm, form_model.form_code, incoming_request)
        elif form_model.is_entity_registration_form():
            message = incorrect_number_of_answers_for_uid_registration_handler(
                dbm, form_model.form_code, incoming_request)
        elif not sent_via_sms_test_questionnaire:
            organization.increment_message_count_for(sms_registration_count=1)

    except Exception as exception:
        if sent_via_sms_test_questionnaire:
            organization.increment_message_count_for(incoming_web_count=1)
        message = handle(exception, incoming_request)

    message = incoming_request.get('error_message', message)
    incoming_request['outgoing_message'] = message if incoming_request.get(
        'is_outgoing_reply_sms_enabled', True) else ""

    if not sent_via_sms_test_questionnaire:

        if incoming_request.get('is_outgoing_reply_sms_enabled', True):
            organization.increment_message_count_for(outgoing_sms_count=1)

        SMS(message=message,
            message_id=incoming_request['message_id'],
            organization=incoming_request['organization'],
            msg_from=mangrove_request.transport.source,
            msg_to=mangrove_request.transport.destination,
            msg_type=MSG_TYPE_SUBMISSION_REPLY,
            status="Submitted").save()

    return incoming_request