def clean(self, value): value = super(SEOrganisationNumberField, self).clean(value) if value in EMPTY_VALUES: return u'' match = SWEDISH_ID_NUMBER.match(value) if not match: raise forms.ValidationError(self.error_messages['invalid']) gd = match.groupdict() # Compare the calculated value with the checksum if id_number_checksum(gd) != int(gd['checksum']): raise forms.ValidationError(self.error_messages['invalid']) # First: check if this is a real organisation_number if valid_organisation(gd): return format_organisation_number(gd) # Is this a single properitor (enskild firma)? try: birth_day = validate_id_birthday(gd, False) return format_personal_id_number(birth_day, gd) except ValueError: raise forms.ValidationError(self.error_messages['invalid'])
def clean(self, value): value = super(SEPersonalIdentityNumberField, self).clean(value) if value in EMPTY_VALUES: return u'' match = SWEDISH_ID_NUMBER.match(value) if match is None: raise forms.ValidationError(self.error_messages['invalid']) gd = match.groupdict() # compare the calculated value with the checksum if id_number_checksum(gd) != int(gd['checksum']): raise forms.ValidationError(self.error_messages['invalid']) # check for valid birthday try: birth_day = validate_id_birthday(gd) except ValueError: raise forms.ValidationError(self.error_messages['invalid']) # make sure that co-ordination numbers do not pass if not allowed if not self.coordination_number and int(gd['day']) > 60: raise forms.ValidationError(self.error_messages['coordination_number']) return format_personal_id_number(birth_day, gd)
def clean(self, value): value = super(SEPersonalIdentityNumberField, self).clean(value) if value in EMPTY_VALUES: return u'' match = SWEDISH_ID_NUMBER.match(value) if match is None: raise forms.ValidationError(self.error_messages['invalid']) gd = match.groupdict() # compare the calculated value with the checksum if id_number_checksum(gd) != int(gd['checksum']): raise forms.ValidationError(self.error_messages['invalid']) # check for valid birthday try: birth_day = validate_id_birthday(gd) except ValueError: raise forms.ValidationError(self.error_messages['invalid']) # make sure that co-ordination numbers do not pass if not allowed if not self.coordination_number and int(gd['day']) > 60: raise forms.ValidationError( self.error_messages['coordination_number']) return format_personal_id_number(birth_day, gd)
def clean(self, value): try: value = super(BirthDateField, self).clean(value) except forms.ValidationError as e: match = SWEDISH_BIRTH_DATE.match(value) if not match: raise e gd = match.groupdict() gd['sign'] = gd['serial'] = gd['checksum'] = '' # check for valid birthday try: birth_day = validate_id_birthday(gd, fix_coordination_number_day=False) except ValueError: raise forms.ValidationError(self.error_messages['invalid']) return format_personal_id_number(birth_day, gd) return value