def _migrate_participant_data(self, old_part, registration): for pd_type, field in self.pd_field_map.iteritems(): if pd_type.column: friendly_value = value = getattr(registration, pd_type.column) elif pd_type == PersonalDataType.title: try: value = {self.title_map[old_part._title]: 1} except KeyError: value = None friendly_value = convert_to_unicode(old_part._title) elif pd_type == PersonalDataType.position: continue else: value = convert_to_unicode( getattr(old_part, PARTICIPANT_ATTR_MAP[pd_type])) if pd_type == PersonalDataType.phone and value: value = normalize_phone_number(value) friendly_value = value if value: field.is_enabled = True if not self.importer.quiet: self.importer.print_info( cformat('%{yellow!}{}%{reset} %{cyan!}{}%{reset}').format( pd_type.name, friendly_value)) registration.data.append( RegistrationData(field_data=field.current_data, data=value))
def _migrate_participant_data(self, old_part, registration): for pd_type, field in self.pd_field_map.iteritems(): if pd_type.column: friendly_value = value = getattr(registration, pd_type.column) elif pd_type == PersonalDataType.title: try: value = {self.title_map[old_part._title]: 1} except KeyError: value = None friendly_value = convert_to_unicode(old_part._title) else: value = convert_to_unicode(getattr(old_part, PARTICIPANT_ATTR_MAP[pd_type])) if pd_type == PersonalDataType.phone and value: value = normalize_phone_number(value) friendly_value = value if value: field.is_enabled = True if not self.importer.quiet: self.importer.print_info(cformat('%{yellow!}{}%{reset} %{cyan!}{}%{reset}') .format(pd_type.name, friendly_value)) registration.data.append(RegistrationData(field_data=field.current_data, data=value))
def test_normalize_phone_number(input, output): assert normalize_phone_number(input) == output
class PhoneField(RegistrationFormFieldBase): name = 'phone' wtf_field_class = wtforms.StringField wtf_field_kwargs = {'filters': [lambda x: normalize_phone_number(x) if x else '']}