def clean(self): cleaned_data = super(SurveyDataForm, self).clean() if 'send_flyers_country' in cleaned_data and 'send_flyers_zip' in cleaned_data: country = cleaned_data['send_flyers_country'] code = cleaned_data['send_flyers_zip'] try: cleaned_data['send_flyers_zip'] = clean_postal_code(country, code) except ValidationError, e: del cleaned_data['send_flyers_zip'] self.add_error('send_flyers_zip', e)
def clean(self): cleaned_data = super(HostingForm, self).clean() if 'country' in cleaned_data and 'zip_code' in cleaned_data: country = cleaned_data['country'] code = cleaned_data['zip_code'] try: cleaned_data['zip_code'] = clean_postal_code(country, code) except ValidationError, e: del cleaned_data['zip_code'] self.add_error('zip_code', e)
def clean(self): cleaned_data = super(OrganizationPaymentForm, self).clean() if 'check_zip' in cleaned_data: country = self.instance.check_country code = cleaned_data['check_zip'] try: cleaned_data['check_zip'] = clean_postal_code(country, code) except ValidationError, e: del cleaned_data['check_zip'] self.add_error('check_zip', e)
def clean(self): cleaned_data = super(SurveyDataForm, self).clean() if 'send_flyers_country' in cleaned_data and 'send_flyers_zip' in cleaned_data: country = cleaned_data['send_flyers_country'] code = cleaned_data['send_flyers_zip'] try: cleaned_data['send_flyers_zip'] = clean_postal_code( country, code) except ValidationError, e: del cleaned_data['send_flyers_zip'] self.add_error('send_flyers_zip', e)
def test_gb_postal__valid1(self): clean_postal_code('GB', 'NW4 9BX')
def test_unhandled_country(self): clean_postal_code('12', ';[]32adf,,,')
def test_us_postal__empty(self): clean_postal_code('US', '')
def test_us_postal__invalid1(self): with self.assertRaises(ValidationError): clean_postal_code('US', 'ABCDEF')
def test_us_postal__valid2(self): clean_postal_code('US', '16801-2345')
def test_us_postal__valid1(self): clean_postal_code('US', '16801')
def test_gb_postal__invalid1(self): with self.assertRaises(ValidationError): clean_postal_code('GB', '12345')
def test_gb_postal__valid3(self): clean_postal_code('GB', 'M3 3BT')
def test_gb_postal__valid2(self): clean_postal_code('GB', 'M32 8BR')