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()
def whitelist_phone(request): phone_number = request.POST.get('phone') if not phone_number or not is_phone_number_valid(phone_number): return get_bogus_arg_error(request) # user bypassed form validation center_id = request.POST.get('center_id') if center_id: if not is_center_id_valid(center_id): return get_bogus_arg_error( request) # user bypassed form validation white_list = Whitelist(creation_date=now(), modification_date=now(), phone_number=phone_number) white_list.full_clean() white_list.save() # refresh the page that sent us here, now with the phone white-listed if center_id: query_args = '?center_id=%s' % center_id return HttpResponseRedirect( reverse('vr_dashboard:search-phones') + query_args) else: query_args = '?phone=%s' % phone_number return HttpResponseRedirect( reverse('vr_dashboard:phone-history') + query_args)
def whitelist_phone(request): phone_number = request.POST.get('phone') if not phone_number or not is_phone_number_valid(phone_number): return get_bogus_arg_error(request) # user bypassed form validation center_id = request.POST.get('center_id') if center_id: if not is_center_id_valid(center_id): return get_bogus_arg_error(request) # user bypassed form validation white_list = Whitelist(creation_date=now(), modification_date=now(), phone_number=phone_number) white_list.full_clean() white_list.save() # refresh the page that sent us here, now with the phone white-listed if center_id: query_args = '?center_id=%s' % center_id return HttpResponseRedirect(reverse('vr_dashboard:search-phones') + query_args) else: query_args = '?phone=%s' % phone_number return HttpResponseRedirect(reverse('vr_dashboard:phone-history') + query_args)