Esempio 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
Esempio n. 2
0
    def get_context_data(self, **kwargs):
        context = super(ResultsView, self).get_context_data(**kwargs)

        context['year'] = int(self.kwargs.get('year') or settings.YEAR)
        context['results_ready'] = context[
            'year'] < settings.YEAR or Phase.get_current() == 'finished'

        return context
Esempio n. 3
0
 def get_form_kwargs(self):
     kwargs = super(VerificationView, self).get_form_kwargs()
     kwargs['user'] = self.request.user
     phase = Phase.get_current()
     if phase == 'nomination':
         kwargs['has_unverified'] = self.request.session.get(
             'unverified_nominations_%s' % CURRENT_YEAR, False)
     elif phase == 'voting':
         kwargs['has_unverified'] = self.request.session.get(
             'unverified_votes_%s' % CURRENT_YEAR, False)
     else:
         kwargs['has_unverified'] = False
     return kwargs
Esempio n. 4
0
def awards_context(request):
    return {
        'year': settings.YEAR,
        'phase': Phase.get_current(),
        'min_year': settings.MIN_YEAR,
        'max_year': settings.MAX_YEAR,
        'max_fic_nominations': settings.MAX_FIC_NOMINATIONS,
        'max_person_nominations': settings.MAX_PERSON_NOMINATIONS,
        'min_different_nominations': settings.MIN_DIFFERENT_NOMINATIONS,
        'discussion_thread': settings.DISCUSSION_THREAD,
        'nomination_thread': settings.NOMINATION_THREAD,
        'voting_thread': settings.VOTING_THREAD,
        'results_thread': settings.RESULTS_THREAD
    }
Esempio n. 5
0
def awards_context(request):
    return {
        'year': settings.YEAR,
        'phase': Phase.get_current(),
        'min_year': settings.MIN_YEAR,
        'max_year': settings.MAX_YEAR,
        'max_fic_nominations': settings.MAX_FIC_NOMINATIONS,
        'max_person_nominations': settings.MAX_PERSON_NOMINATIONS,
        'min_different_nominations': settings.MIN_DIFFERENT_NOMINATIONS,
        'discussion_thread': settings.DISCUSSION_THREAD,
        'nomination_thread': settings.NOMINATION_THREAD,
        'voting_thread': settings.VOTING_THREAD,
        'results_thread': settings.RESULTS_THREAD
    }
Esempio n. 6
0
 def __init__(self, user, *args, **kwargs):
     self.user = user
     self.made_unverified = kwargs.pop('has_unverified', False)
     super(VerificationForm, self).__init__(*args, **kwargs)
     has_unverified = False
     if user.member:
         del self.fields['profile_url']
         if not self.made_unverified:
             phase = Phase.get_current()
             if phase == 'nomination':
                 has_unverified = user.member.nominations_by.from_year(
                 ).filter(verified=False).exists()
             elif phase == 'voting':
                 has_unverified = user.member.votes.from_year().filter(
                     verified=False).exists()
     if not has_unverified:
         del self.fields['verify_current']
Esempio n. 7
0
    def clean(self):
        phase = Phase.get_current()
        if phase > 'nomination':
            raise ValidationError(u"The nomination phase has ended! Better luck next year.")
        elif phase < 'nomination':
            raise ValidationError(u"The nomination phase hasn't started yet! Have patience until nominations open.")
        # By this point all nominations will have been saved to the
        # database, so we can safely assume they have PKs.
        fic_nominations = defaultdict(int)
        person_nominations = defaultdict(int)
        award_dict = defaultdict(list)

        for form in self.forms:
            if not form.is_empty() and form.is_valid():
                if 'fic' in form.fields:
                    if form.has_changed():
                        fic = form.cleaned_data['fic']
                    else:
                        fic = form.instance.fic
                    fic_nominations[fic] += 1
                    for author in fic.authors.all():
                        person_nominations[author] += 1
                if 'nominee' in form.fields:
                    if form.has_changed():
                        author = form.cleaned_data['nominee']
                    else:
                        author = form.instance.nominee
                    person_nominations[author] += 1
                if form.award in award_dict:
                    for other_form in award_dict[form.award]:
                        if not form.is_distinct_from(other_form):
                            form.errors['__all__'] = form.error_class([u"You cannot make the same nomination twice in the same category."])
                award_dict[form.award].append(form)


        for (fic, nominations) in fic_nominations.items():
            if nominations > settings.MAX_FIC_NOMINATIONS:
                raise ValidationError(u"You have nominated %(fic)s %(nominations)s times. You may only nominate any given fic up to %(max_nominations)s times. Please remove some nominations for %(fic)s." % {'fic': fic, 'nominations': nominations, 'max_nominations': settings.MAX_FIC_NOMINATIONS})

        for (person, nominations) in person_nominations.items():
            if nominations > settings.MAX_PERSON_NOMINATIONS:
                raise ValidationError(u"You have nominated %(person)s or their work %(nominations)s times. You may only nominate a given person up to %(max_nominations)s times. Please remove some nominations for %(person)s." % {'person': person, 'nominations': nominations, 'max_nominations': settings.MAX_PERSON_NOMINATIONS})

        if len(person_nominations) < settings.MIN_DIFFERENT_NOMINATIONS:
            raise ValidationError(u"You must nominate at least %s different authors." % settings.MIN_DIFFERENT_NOMINATIONS)
Esempio n. 8
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
Esempio n. 9
0
    def clean(self):
        phase = Phase.get_current()
        if phase > 'nomination':
            raise ValidationError(
                u"The nomination phase has ended! Better luck next year.")
        elif phase < 'nomination':
            raise ValidationError(
                u"The nomination phase hasn't started yet! Have patience until nominations open."
            )
        # By this point all nominations will have been saved to the
        # database, so we can safely assume they have PKs.
        fic_nominations = defaultdict(int)
        person_nominations = defaultdict(int)
        award_dict = defaultdict(list)

        for form in self.forms:
            if not form.is_empty() and form.is_valid():
                if 'fic' in form.fields:
                    if form.has_changed():
                        fic = form.cleaned_data['fic']
                    else:
                        fic = form.instance.fic
                    fic_nominations[fic] += 1
                    for author in fic.authors.all():
                        person_nominations[author] += 1
                if 'nominee' in form.fields:
                    if form.has_changed():
                        author = form.cleaned_data['nominee']
                    else:
                        author = form.instance.nominee
                    person_nominations[author] += 1
                if form.award in award_dict:
                    for other_form in award_dict[form.award]:
                        if not form.is_distinct_from(other_form):
                            form.errors['__all__'] = form.error_class([
                                u"You cannot make the same nomination twice in the same category."
                            ])
                award_dict[form.award].append(form)

        for (fic, nominations) in fic_nominations.items():
            if nominations > settings.MAX_FIC_NOMINATIONS:
                raise ValidationError(
                    u"You have nominated %(fic)s %(nominations)s times. You may only nominate any given fic up to %(max_nominations)s times. Please remove some nominations for %(fic)s."
                    % {
                        'fic': fic,
                        'nominations': nominations,
                        'max_nominations': settings.MAX_FIC_NOMINATIONS
                    })

        for (person, nominations) in person_nominations.items():
            if nominations > settings.MAX_PERSON_NOMINATIONS:
                raise ValidationError(
                    u"You have nominated %(person)s or their work %(nominations)s times. You may only nominate a given person up to %(max_nominations)s times. Please remove some nominations for %(person)s."
                    % {
                        'person': person,
                        'nominations': nominations,
                        'max_nominations': settings.MAX_PERSON_NOMINATIONS
                    })

        if len(person_nominations) < settings.MIN_DIFFERENT_NOMINATIONS:
            raise ValidationError(
                u"You must nominate at least %s different authors." %
                settings.MIN_DIFFERENT_NOMINATIONS)