예제 #1
0
파일: forms.py 프로젝트: Rocky443/Tabbie
    def save(self):
        # Unconfirm the other, if necessary
        if self.cleaned_data['confirmed']:
            if self.debate.confirmed_ballot != self.ballots and self.debate.confirmed_ballot is not None:
                self.debate.confirmed_ballot.confirmed = False
                self.debate.confirmed_ballot.save()

        bs = BallotSet(self.ballots)

        def do(side):
            for i in self.POSITIONS:
                speaker = self.cleaned_data['%s_speaker_%d' % (side, i)]
                bs.set_speaker(side, i, speaker)
                for adj in self.adjudicators:
                    score = self.cleaned_data[self.score_field_name(
                        adj, side, i)]
                    bs.set_score(adj, side, i, score)

        do('aff')
        do('neg')

        bs.motion = self.cleaned_data['motion']
        bs.aff_motion_veto = self.cleaned_data['aff_motion_veto']
        bs.neg_motion_veto = self.cleaned_data['neg_motion_veto']
        bs.discarded = self.cleaned_data['discarded']
        bs.confirmed = self.cleaned_data['confirmed']

        bs.save()

        self.debate.result_status = self.cleaned_data['debate_result_status']
        self.debate.save()
예제 #2
0
파일: forms.py 프로젝트: kgpdebsoc/tabbycat
    def _initial_data(self):
        """Generates dictionary of initial form data."""

        ballotset = BallotSet(self.ballotsub)
        initial = {
            'debate_result_status': self.debate.result_status,
            'confirmed': ballotset.confirmed,
            'discarded': ballotset.discarded
        }

        # HACK: Check here to see if self.ballotsub has been saved -- if it's not,
        # then it's a new ballot set, and choose_sides should not be populated
        # with an initial value. Fix when models support a proper "no side
        # assigned" state (it currently doesn't).
        if self.choosing_sides and self.ballotsub.pk is not None:
            try:
                initial['choose_sides'] = str(
                    self.debate.aff_team.id) + "," + str(
                        self.debate.neg_team.id)
            except m.DebateTeam.DoesNotExist:
                pass

        # Generally, initialise the motion to what is currently in the database.
        # But if there is only one motion and no motion is currently stored in
        # the database for this round, then default to the only motion there is.
        if self.using_motions:
            if not ballotset.motion and self.motions.count() == 1:
                initial['motion'] = self.motions.get()
            else:
                initial['motion'] = ballotset.motion
            for side in self.SIDES:
                initial[self._fieldname_motion_veto(
                    side)] = ballotset.get_motion_veto(side)

        for side, pos in self.SIDES_AND_POSITIONS:
            speaker = ballotset.get_speaker(side, pos)
            if speaker:
                initial[self._fieldname_speaker(side, pos)] = speaker.pk
                for adj in self.adjudicators:
                    score = ballotset.get_score(adj, side, pos)
                    initial[self._fieldname_score(adj, side, pos)] = score

        return initial
예제 #3
0
    def save(self):

        # 1. Unconfirm the other, if necessary
        if self.cleaned_data['confirmed']:
            if self.debate.confirmed_ballot != self.ballots and self.debate.confirmed_ballot is not None:
                self.debate.confirmed_ballot.confirmed = False
                self.debate.confirmed_ballot.save()

        # 2. Check if there was a forfeit
        if self.using_forfeits and self.forfeit_declared:
            if self.cleaned_data['forfeits'] == "aff_forfeit":
                forfeiter = self.debate.aff_dt
            if self.cleaned_data['forfeits'] == "neg_forfeit":
                forfeiter = self.debate.neg_dt
            bs = ForfeitBallotSet(self.ballots, forfeiter)
        else:
            bs = BallotSet(self.ballots)

        # 3. Save the sides
        if self.choosing_sides:
            bs.set_sides(*self.cleaned_data['choose_sides'])

        # 4. Save motions
        if self.using_motions:
            bs.motion = self.cleaned_data['motion']

        if self.using_vetoes:
            for side in self.SIDES:
                motion_veto = self.cleaned_data[self._fieldname_motion_veto(
                    side)]
                bs.set_motion_veto(side, motion_veto)

        # 5. Save speaker fields
        if not self.forfeit_declared:
            print "saving speaker fields"
            for side, pos in self.SIDES_AND_POSITIONS:
                speaker = self.cleaned_data[self._fieldname_speaker(side, pos)]
                bs.set_speaker(side, pos, speaker)
                for adj in self.adjudicators:
                    score = self.cleaned_data[self._fieldname_score(
                        adj, side, pos)]
                    bs.set_score(adj, side, pos, score)

        # 6. Save status fields
        bs.discarded = self.cleaned_data['discarded']
        bs.confirmed = self.cleaned_data['confirmed']
        bs.save()

        self.debate.result_status = self.cleaned_data['debate_result_status']
        self.debate.save()
예제 #4
0
    def _initial_data(self):
        """Generates dictionary of initial form data."""

        ballotset = BallotSet(self.ballotsub)
        initial = {'debate_result_status': self.debate.result_status,
                'confirmed': ballotset.confirmed, 'discarded': ballotset.discarded}

        # HACK: Check here to see if self.ballotsub has been saved -- if it's not,
        # then it's a new ballot set, and choose_sides should not be populated
        # with an initial value. Fix when models support a proper "no side
        # assigned" state (it currently doesn't).
        if self.choosing_sides and self.ballotsub.pk is not None:
            try:
                initial['choose_sides'] = str(self.debate.aff_team.id) + "," + str(self.debate.neg_team.id)
            except m.DebateTeam.DoesNotExist:
                pass

        # Generally, initialise the motion to what is currently in the database.
        # But if there is only one motion and no motion is currently stored in
        # the database for this round, then default to the only motion there is.
        if self.using_motions:
            if not ballotset.motion and self.motions.count() == 1:
                initial['motion'] = self.motions.get()
            else:
                initial['motion'] = ballotset.motion
            for side in self.SIDES:
                initial[self._fieldname_motion_veto(side)] = ballotset.get_motion_veto(side)

        for side, pos in self.SIDES_AND_POSITIONS:
            speaker = ballotset.get_speaker(side, pos)
            if speaker:
                initial[self._fieldname_speaker(side, pos)] = speaker.pk
                for adj in self.adjudicators:
                    score = ballotset.get_score(adj, side, pos)
                    initial[self._fieldname_score(adj, side, pos)] = score

        return initial
예제 #5
0
파일: forms.py 프로젝트: Rocky443/Tabbie
    def _initial_data(self):
        """
        Generate dictionary of initial form data
        """

        initial = {'debate_result_status': self.debate.result_status}

        bs = BallotSet(self.ballots)

        initial['confirmed'] = bs.confirmed
        initial['discarded'] = bs.discarded

        # This isn't relevant if we're not showing the motions field
        # (i.e. there are no motions given for this round).
        # Generally, initialise the motion to what is currently in the
        # database.  But if there is only one motion and no motion is
        # currently stored in the database for this round, then default
        # to the only motion there is.
        if self.show_motion:
            if not bs.motion and self.motions.count() == 1:
                initial['motion'] = self.motions.get()
            else:
                initial['motion'] = bs.motion
            initial['aff_motion_veto'] = bs.aff_motion_veto
            initial['neg_motion_veto'] = bs.neg_motion_veto

        for side in ('aff', 'neg'):
            for i in self.POSITIONS:
                speaker = bs.get_speaker(side, i)
                if speaker:
                    initial['%s_speaker_%d' % (side, i)] = speaker.id

                    for adj in self.adjudicators:
                        score = bs.get_score(adj, side, i)
                        initial[self.score_field_name(adj, side, i)] = score

        return initial
예제 #6
0
def add_ballot_set(debate,
                   submitter_type,
                   user,
                   discarded=False,
                   confirmed=False,
                   min_score=72,
                   max_score=78):

    if discarded and confirmed:
        raise ValueError("Ballot can't be both discarded and confirmed!")

    # Create a new BallotSubmission
    bsub = m.BallotSubmission(submitter_type=submitter_type, debate=debate)
    if submitter_type == m.BallotSubmission.SUBMITTER_TABROOM:
        bsub.submitter = user
    bsub.save()

    def gen_results():
        r = {'aff': (0, ), 'neg': (0, )}

        def do():
            s = [
                random.randint(min_score, max_score) for i in range(
                    debate.round.tournament.LAST_SUBSTANTIVE_POSITION)
            ]
            s.append(random.randint(min_score, max_score) / 2.0)
            return s

        while sum(r['aff']) == sum(r['neg']):
            r['aff'] = do()
            r['neg'] = do()
        return r

    rr = dict()
    for adj in debate.adjudicators.list:
        rr[adj] = gen_results()

    # Create relevant scores
    bset = BallotSet(bsub)

    for side in ('aff', 'neg'):
        speakers = getattr(debate, '%s_team' % side).speakers
        for i in range(1,
                       debate.round.tournament.LAST_SUBSTANTIVE_POSITION + 1):
            bset.set_speaker(
                team=side,
                position=i,
                speaker=speakers[i - 1],
            )
        bset.set_speaker(team=side,
                         position=debate.round.tournament.REPLY_POSITION,
                         speaker=speakers[0])

        for adj in debate.adjudicators.list:
            for pos in debate.round.tournament.POSITIONS:
                bset.set_score(adj, side, pos, rr[adj][side][pos - 1])

    # Pick a motion
    motions = debate.round.motion_set.all()
    if motions:
        motion = random.choice(motions)
        bset.motion = motion

    bset.discarded = discarded
    bset.confirmed = confirmed

    bset.save()

    # If the ballot is confirmed, the debate should be too.
    if confirmed:
        debate.result_status = m.Debate.STATUS_CONFIRMED
        debate.save()

    return bset
예제 #7
0
def add_ballot_set(debate, submitter_type, user, discarded=False, confirmed=False, min_score=72, max_score=78):

    if discarded and confirmed:
        raise ValueError("Ballot can't be both discarded and confirmed!")

    # Create a new BallotSubmission
    bsub = m.BallotSubmission(submitter_type=submitter_type, debate=debate)
    if submitter_type == m.BallotSubmission.SUBMITTER_TABROOM:
        bsub.submitter = user
    bsub.save()

    def gen_results():
        r = {'aff': (0,), 'neg': (0,)}
        def do():
            s = [random.randint(min_score, max_score) for i in range(debate.round.tournament.LAST_SUBSTANTIVE_POSITION)]
            s.append(random.randint(min_score, max_score)/2.0)
            return s
        while sum(r['aff']) == sum(r['neg']):
            r['aff'] = do()
            r['neg'] = do()
        return r

    rr = dict()
    for adj in debate.adjudicators.list:
        rr[adj] = gen_results()

    # Create relevant scores
    bset = BallotSet(bsub)

    for side in ('aff', 'neg'):
        speakers = getattr(debate, '%s_team' % side).speakers
        for i in range(1, debate.round.tournament.LAST_SUBSTANTIVE_POSITION+1):
            bset.set_speaker(
                team = side,
                position = i,
                speaker = speakers[i - 1],
            )
        bset.set_speaker(
            team = side,
            position = debate.round.tournament.REPLY_POSITION,
            speaker = speakers[0]
        )

        for adj in debate.adjudicators.list:
            for pos in debate.round.tournament.POSITIONS:
                bset.set_score(adj, side, pos, rr[adj][side][pos-1])

    # Pick a motion
    motions = debate.round.motion_set.all()
    if motions:
        motion = random.choice(motions)
        bset.motion = motion

    bset.discarded = discarded
    bset.confirmed = confirmed

    bset.save()

    # If the ballot is confirmed, the debate should be too.
    if confirmed:
        debate.result_status = m.Debate.STATUS_CONFIRMED
        debate.save()

    return bset
예제 #8
0
 def _get_ballotset(self):
     ballotsub = m.BallotSubmission.objects.get(debate=self.debate, confirmed=True)
     return BallotSet(ballotsub)
예제 #9
0
    def _save_complete_ballotset(self, teams, testdata, post_ballotset_create=None):
        # unconfirm existing ballot
        try:
            existing = m.BallotSubmission.objects.get(debate=self.debate, confirmed=True)
        except m.BallotSubmission.DoesNotExist:
            pass
        else:
            existing.confirmed = False
            existing.save()

        ballotsub = m.BallotSubmission(debate=self.debate, submitter_type=m.BallotSubmission.SUBMITTER_TABROOM)
        ballotset = BallotSet(ballotsub)
        if post_ballotset_create:
            post_ballotset_create(ballotset)
        scores = testdata['scores']

        for team in teams:
            speakers = self._get_team(team).speaker_set.all()
            for pos, speaker in enumerate(speakers, start=1):
                ballotset.set_speaker(team, pos, speaker)
            ballotset.set_speaker(team, 4, speakers[0])

        for adj, sheet in zip(self.adjs, scores):
            for team, teamscores in zip(teams, sheet):
                for pos, score in enumerate(teamscores, start=1):
                    ballotset.set_score(adj, team, pos, score)

        ballotset.confirmed = True
        ballotset.save()

        return ballotset