Beispiel #1
0
    def clean(self):
        cleaned_data = self.cleaned_data

        ssn = cleaned_data.get('ssn', '')
        country = cleaned_data.get('country')
        birthday = cleaned_data.get('birthday', '')
        distance = cleaned_data.get('distance', '')

        if country == 'LV':
            try:
                if not ssn or not len(ssn) == 11:
                    self._errors.update({'ssn': [_("Invalid Social Security Number."), ]})
                checksum = 1
                for i in xrange(10):
                    checksum -= int(ssn[i]) * int("01060307091005080402"[i * 2:i * 2 + 2])
                if not int(checksum - math.floor(checksum / 11) * 11) == int(ssn[10]):
                    self._errors.update({'ssn': [_("Invalid Social Security Number."), ]})
            except:
                self._errors.update({'ssn': [_("Invalid Social Security Number."), ]})

        else:
            if not birthday:
                self._errors.update({'birthday': [_("Birthday is required."), ]})

        if birthday and distance:
            total = get_total(self.instance.application.competition, distance.id, birthday.year)
            if not total:
                self._errors.update({'distance': [_("This distance not available for this participant."), ]})

        return cleaned_data
Beispiel #2
0
    def save(self, commit=True):
        obj = super(ParticipantInlineForm, self).save(commit=False)

        obj.competition = self.application.competition
        obj.insurance_id = self.cleaned_data.get('insurance')

        if obj.birthday and obj.distance and self.application.payment_status == self.application.PAY_STATUS_NOT_PAYED:
            total = get_total(obj.competition, obj.distance_id, obj.birthday.year, obj.insurance_id)
            if total:
                obj.price = total.get('price_obj', None)
            else:
                obj.price = None

        if commit:
            obj.save()

        return obj