Exemplo n.º 1
0
    def clean(self):
        phase = Phase.get_current()
        if phase > 'voting':
            raise ValidationError(
                u"The voting phase has ended! Better luck next year.")
        elif phase < 'voting':
            raise ValidationError(
                u"The voting phase hasn't started yet! Have patience until voting opens."
            )

        votes = []
        for field in self.fields:
            vote = self.cleaned_data.get(field)
            if vote:
                vote_obj = Vote(member=self.member,
                                year=self.year,
                                award_id=self.fields[field].award.pk,
                                nomination=vote)
                try:
                    vote_obj.clean()
                except ValidationError as e:
                    self.add_error(field, e)
                votes.append(vote_obj)
        if len(votes) * 2 < len(self.fields):
            raise ValidationError(
                u"You must place a vote in at least half of the available categories."
            )
        return self.cleaned_data
Exemplo n.º 2
0
 def save(self, commit=True):
     votes = []
     for year_award in YearAward.objects.from_year(self.year):
         vote = self.cleaned_data.get('award_%s' % year_award.award_id)
         if vote:
             try:
                 vote_obj = Vote.objects.from_year(self.year).get(member=self.member, award_id=year_award.award_id)
             except Vote.DoesNotExist:
                 vote_obj = Vote(member=self.member, year=self.year, award_id=year_award.award_id)
             vote_obj.nomination = vote
             if commit:
                 vote_obj.save()
             votes.append(vote_obj)
     return votes
Exemplo n.º 3
0
 def save(self, commit=True):
     votes = []
     for year_award in YearAward.objects.from_year(self.year):
         vote = self.cleaned_data.get('award_%s' % year_award.award_id)
         if vote:
             try:
                 vote_obj = Vote.objects.from_year(self.year).get(
                     member=self.member, award_id=year_award.award_id)
             except Vote.DoesNotExist:
                 vote_obj = Vote(member=self.member,
                                 year=self.year,
                                 award_id=year_award.award_id)
             vote_obj.nomination = vote
             if commit:
                 vote_obj.save()
             votes.append(vote_obj)
     return votes
Exemplo n.º 4
0
    def clean(self):
        phase = Phase.get_current()
        if phase > 'voting':
            raise ValidationError(u"The voting phase has ended! Better luck next year.")
        elif phase < 'voting':
            raise ValidationError(u"The voting phase hasn't started yet! Have patience until voting opens.")

        votes = []
        for field in self.fields:
            vote = self.cleaned_data.get(field)
            if vote:
                vote_obj = Vote(member=self.member, year=self.year, award_id=self.fields[field].award.pk, nomination=vote)
                try:
                    vote_obj.clean()
                except ValidationError as e:
                    self.add_error(field, e)
                votes.append(vote_obj)
        if len(votes) * 2 < len(self.fields):
            raise ValidationError(u"You must place a vote in at least half of the available categories.")
        return self.cleaned_data