コード例 #1
0
ファイル: views.py プロジェクト: adamslapins/velo.lv
    def validate(self):
        self.participants = self.object.participant_set.all()

        now = timezone.now()

        valid = True

        if self.participants.count() == 0:
            messages.error(self.request, _('Please add at least one participant'))
            valid = False

        for participant in self.participants:
            if not participant.last_name or not participant.first_name:
                messages.error(self.request, _('Please specify first name and last name for all participants'))
                valid = False
            elif not participant.birthday:
                messages.error(self.request, _('Please specify birthday for all participants'))
                valid = False
            elif not participant.price:
                messages.error(self.request, _('Not all participants have price added. Did you press save & pay?'))
                valid = False
            else:
                if not self.object.external_invoice_code and not participant.is_participating:
                    if participant.price.start_registering > now or participant.price.end_registering < now:
                        participant.price = None
                        participant.save()
                        if valid:
                            messages.error(self.request, _('Price expired. Start registering participants from step 1.'))
                        valid = False
                # check if prices are still valid
            if valid:
                self.total_entry_fee += get_participant_fee_from_price(self.object.competition, participant.price)
                if participant.insurance:
                    self.total_insurance_fee += get_insurance_fee_from_insurance(self.object.competition, participant.insurance)

        if valid:
            if self.object.total_entry_fee != self.total_entry_fee or self.object.total_insurance_fee != self.total_insurance_fee:
                self.object.total_entry_fee = self.total_entry_fee
                self.object.total_insurance_fee = self.total_insurance_fee
                # This is recalculated on model
                # self.object.final_price = self.total_entry_fee + self.total_insurance_fee + float(self.object.donation)
                self.object.save()
            return None
        else:
            return HttpResponseRedirect(reverse('application', kwargs={'slug': self.object.code}))
コード例 #2
0
ファイル: velomath.py プロジェクト: adamslapins/velo.lv
def getInsurancePrice(insurance, competition):
    if not insurance:
        return None
    return get_insurance_fee_from_insurance(competition, insurance)