Exemplo n.º 1
0
def get_one_way_number_for_recipient(recipient):
    if isinstance(recipient, CouchUser):
        return recipient.phone_number
    elif is_commcarecase(recipient):
        one_way_number = recipient.get_case_property('contact_phone_number')
        one_way_number = apply_leniency(one_way_number)
        if one_way_number:
            try:
                CommCareMobileContactMixin.validate_number_format(one_way_number)
                return one_way_number
            except InvalidFormatException:
                return None
    return None
Exemplo n.º 2
0
def get_one_way_number_for_recipient(recipient):
    if isinstance(recipient, CouchUser):
        return recipient.phone_number
    elif is_commcarecase(recipient):
        one_way_number = recipient.get_case_property('contact_phone_number')
        one_way_number = apply_leniency(one_way_number)
        if one_way_number:
            try:
                CommCareMobileContactMixin.validate_number_format(one_way_number)
                return one_way_number
            except InvalidFormatException:
                return None
    return None
Exemplo n.º 3
0
def get_unverified_number_for_recipient(recipient):
    if isinstance(recipient, CouchUser):
        try:
            return recipient.phone_number
        except Exception:
            # todo: catch more specific error
            return None
    elif isinstance(recipient, CommCareCase):
        unverified_number = recipient.get_case_property("contact_phone_number")
        unverified_number = apply_leniency(unverified_number)
        if unverified_number:
            try:
                CommCareMobileContactMixin.validate_number_format(unverified_number)
                return unverified_number
            except InvalidFormatException:
                return None
    return None
Exemplo n.º 4
0
def get_unverified_number_for_recipient(recipient):
    if isinstance(recipient, CouchUser):
        try:
            return recipient.phone_number
        except Exception:
            # todo: catch more specific error
            return None
    elif is_commcarecase(recipient):
        unverified_number = recipient.get_case_property("contact_phone_number")
        unverified_number = apply_leniency(unverified_number)
        if unverified_number:
            try:
                CommCareMobileContactMixin.validate_number_format(
                    unverified_number)
                return unverified_number
            except InvalidFormatException:
                return None
    return None
Exemplo n.º 5
0
def get_recipient_phone_number(reminder, recipient, verified_numbers):
    verified_number = verified_numbers.get(recipient.get_id, None)
    unverified_number = None

    if verified_number is None:
        if isinstance(recipient, CouchUser):
            try:
                unverified_number = recipient.phone_number
            except Exception:
                unverified_number = None
        elif isinstance(recipient, CommCareCase):
            unverified_number = recipient.get_case_property("contact_phone_number")
            unverified_number = apply_leniency(unverified_number)
            if unverified_number:
                try:
                    CommCareMobileContactMixin.validate_number_format(unverified_number)
                except InvalidFormatException:
                    unverified_number = None
            else:
                unverified_number = None

    return (verified_number, unverified_number)
Exemplo n.º 6
0
def get_recipient_phone_number(reminder, recipient, verified_numbers):
    verified_number = verified_numbers.get(recipient.get_id, None)
    unverified_number = None

    if verified_number is None:
        if isinstance(recipient, CouchUser):
            try:
                unverified_number = recipient.phone_number
            except Exception:
                unverified_number = None
        elif isinstance(recipient, CommCareCase):
            unverified_number = recipient.get_case_property(
                "contact_phone_number")
            unverified_number = apply_leniency(unverified_number)
            if unverified_number:
                try:
                    CommCareMobileContactMixin.validate_number_format(
                        unverified_number)
                except InvalidFormatException:
                    unverified_number = None
            else:
                unverified_number = None

    return (verified_number, unverified_number)