Example #1
0
    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'])
Example #2
0
    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'])
Example #3
0
    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)
Example #4
0
    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)