Exemplo n.º 1
0
    def failed_submission_log(cls):
        organization = Mock(spec=Organization)
        organization.org_id = "SLX364903"
        cls.datawinners_log1 = DatawinnerLog(
            message="12 november 2014 post number 2",
            from_number="0330307221",
            to_number="919880734937",
            organization_id=organization.org_id,
            error=
            "Error. Questionnaire Code Hello is incorrect. Find the Code on the top of the printed Questionnaire and resend SMS starting with this Code. "
        )

        cls.datawinners_log2 = DatawinnerLog(
            message="12 november 2014 post number 2",
            from_number="0330307221",
            to_number="919880734937",
            organization_id=organization.org_id,
            error=
            "Error. Questionnaire Code Hello is incorrect. Find the Code on the top of the printed Questionnaire and resend SMS starting with this Code. "
        )

        cls.datawinners_log3 = DatawinnerLog(
            message="12 november 2014 post number 2",
            from_number="0330307221",
            to_number="919880734937",
            organization_id=organization.org_id,
            error=
            "Error. Questionnaire Code Hello is incorrect. Find the Code on the top of the printed Questionnaire and resend SMS starting with this Code. "
        )
        cls.datawinners_log1.save()
        cls.datawinners_log2.save()
        cls.datawinners_log3.save()
Exemplo n.º 2
0
def create_failure_log(error_message, request):
    log = DatawinnerLog()
    log.error = error_message
    log.form_code = request.get(FORM_CODE, '')
    log.message = request.get('incoming_message')
    log.from_number = request['transport_info'].source
    log.to_number = request['transport_info'].destination
    log.organization = request.get('organization')
    log.save()
Exemplo n.º 3
0
def sms(request):
    _message = request.POST["message"]
    _from, _to = _get_from_and_to_numbers(request)
    try:
        dbm = get_db_manager_for(_to)
        sms_player = SMSPlayer(dbm, SubmissionHandler(dbm))
        transportInfo = TransportInfo(transport=SMS, source=_from, destination=_to)
        response = sms_player.accept(Request(transportInfo=transportInfo, message=_message))
        message = SMSResponse(response).text()

    except (SubmissionParseException, FormModelDoesNotExistsException,) as exception:
        message = get_exception_message_for(exception=exception, channel=SMS)
        log = DatawinnerLog(message=_message, from_number=_from, to_number=_to, form_code=exception.data[0],
                            error=message)
        log.save()
    except NumberNotRegisteredException as exception:
        message = get_exception_message_for(exception=exception, channel=SMS)
        log = DatawinnerLog(message=_message, from_number=_from, to_number=_to, form_code=None, error=message)
        log.save()
    except MangroveException as exception:
        message = get_exception_message_for(exception=exception, channel=SMS)
    except Exception as exception:
        logger.exception('SMS Processing failure: message')
        message = get_exception_message_for(exception=exception, channel=SMS)

    return HttpResponse(message)
Exemplo n.º 4
0
def sms(request):
    _message = request.POST["message"]
    _from, _to = _get_from_and_to_numbers(request)
    try:
        dbm = get_db_manager_for(_to)
        sms_player = SMSPlayer(dbm, SubmissionHandler(dbm))
        transportInfo = TransportInfo(transport=SMS,
                                      source=_from,
                                      destination=_to)
        response = sms_player.accept(
            Request(transportInfo=transportInfo, message=_message))
        message = SMSResponse(response).text()

    except (
            SubmissionParseException,
            FormModelDoesNotExistsException,
    ) as exception:
        message = get_exception_message_for(exception=exception, channel=SMS)
        log = DatawinnerLog(message=_message,
                            from_number=_from,
                            to_number=_to,
                            form_code=exception.data[0],
                            error=message)
        log.save()
    except NumberNotRegisteredException as exception:
        message = get_exception_message_for(exception=exception, channel=SMS)
        log = DatawinnerLog(message=_message,
                            from_number=_from,
                            to_number=_to,
                            form_code=None,
                            error=message)
        log.save()
    except MangroveException as exception:
        message = get_exception_message_for(exception=exception, channel=SMS)
    except Exception as exception:
        logger.exception('SMS Processing failure: message')
        message = get_exception_message_for(exception=exception, channel=SMS)

    return HttpResponse(message)