Пример #1
0
def sms_change_type(request, event_id, new_type, return_to=HotlineEvent.TYPE_SMS_UNKNOWN):

    try:
        event = HotlineEvent.objects.get(id=int(event_id))
        event.event_type = new_type
        event.save()
    except (HotlineEvent.DoesNotExist, ValueError):
        pass

    if event and event.event_type == HotlineEvent.TYPE_SMS_USHAHIDI:
        make_ushahidi_request(event)

    return redirect("sms_filter", return_to)
def handle_sms_call(payload, event_type=None):

    identity = normalize_phone_number(payload.get('from').strip())
    if not is_valid_number(identity) or number_is_blacklisted(identity):
        return

    message = payload.get('message').strip()
    if not len(message):
        message = None

    if event_type is None:
        event_type = event_type_from_message(message)

    phone_number = payload.get('phone_number')
    timestamp = payload.get('timestamp')
    received_on = datetime_from_timestamp(timestamp)
    operator = operator_from_mali_number(identity)

    try:
        existing = HotlineEvent.objects.get(identity=identity,
                                            processed=False)
    except HotlineEvent.DoesNotExist:
        existing = None

    # if same number calls again before previous request has been treated
    # we just update the date of the event.
    if existing:
        print(existing)
        existing.received_on = received_on
        existing.save()
        return

    try:
        event = HotlineEvent.objects.create(
            identity=identity,
            event_type=event_type,
            hotline_number=phone_number,
            received_on=received_on,
            sms_message=message,
            operator=operator)
    except:
        return

    if event.event_type == HotlineEvent.TYPE_SMS_USHAHIDI:
        event.processed = False
        make_ushahidi_request(event)

    send_notification(event)
    return
Пример #3
0
def sms_change_type(request,
                    event_id,
                    new_type,
                    return_to=HotlineEvent.TYPE_SMS_UNKNOWN):

    try:
        event = HotlineEvent.objects.get(id=int(event_id))
        event.event_type = new_type
        event.save()
    except (HotlineEvent.DoesNotExist, ValueError):
        pass

    if event and event.event_type == HotlineEvent.TYPE_SMS_USHAHIDI:
        make_ushahidi_request(event)

    return redirect('sms_filter', return_to)
def handle_sms_call(payload, event_type=None):

    identity = normalize_phone_number(payload.get('from').strip())
    if not is_valid_number(identity) or number_is_blacklisted(identity):
        return

    message = payload.get('message').strip()
    if not len(message):
        message = None

    if event_type is None:
        event_type = event_type_from_message(message)

    phone_number = payload.get('phone_number')
    timestamp = payload.get('timestamp')
    received_on = datetime_from_timestamp(timestamp)
    operator = operator_from_mali_number(identity)

    try:
        existing = HotlineEvent.objects.get(identity=identity, processed=False)
    except HotlineEvent.DoesNotExist:
        existing = None

    # if same number calls again before previous request has been treated
    # we just update the date of the event.
    if existing:
        print(existing)
        existing.received_on = received_on
        existing.save()
        return

    try:
        event = HotlineEvent.objects.create(identity=identity,
                                            event_type=event_type,
                                            hotline_number=phone_number,
                                            received_on=received_on,
                                            sms_message=message,
                                            operator=operator)
    except:
        return

    if event.event_type == HotlineEvent.TYPE_SMS_USHAHIDI:
        event.processed = False
        make_ushahidi_request(event)

    send_notification(event)
    return