def ensure_staff_phone_exists(staff_phone_number,
                              center,
                              staff_phones,
                              creation_date=None):
    """ Given a staff phone number and center, ensure that a corresponding StaffPhone
    exists.  White-list about half of them, and maintain a list of StaffPhones that
    have been created.
    """
    staff_phone = StaffPhone(phone_number=staff_phone_number,
                             registration_center=center)
    try:
        staff_phone.full_clean()
    except ValidationError:
        return  # assume staff phone exists
    if creation_date:
        staff_phone.creation_date = creation_date
    staff_phone.save()

    staff_phones.append(staff_phone)

    # white-list half of them
    if random.choice((1, 2)) == 1:
        w = Whitelist(phone_number=staff_phone.phone_number)
        w.full_clean()
        w.save()
Example #2
0
def ensure_staff_phone_exists(staff_phone_number, center, staff_phones, creation_date=None):
    """ Given a staff phone number and center, ensure that a corresponding StaffPhone
    exists.  White-list about half of them, and maintain a list of StaffPhones that
    have been created.
    """
    staff_phone = StaffPhone(phone_number=staff_phone_number, registration_center=center)
    try:
        staff_phone.full_clean()
    except ValidationError:
        return  # assume staff phone exists
    if creation_date:
        staff_phone.creation_date = creation_date
    staff_phone.save()

    staff_phones.append(staff_phone)

    # white-list half of them
    if random.choice((1, 2)) == 1:
        w = Whitelist(phone_number=staff_phone.phone_number)
        w.full_clean()
        w.save()