コード例 #1
0
ファイル: tests.py プロジェクト: shdwpuppet/lanserver
 def test_away_win(self):
     match = self.create_match()
     record = Result()
     record.match = match
     record.record_result(t1=match.home_team, t2=match.away_team, s1=3, s2=5)
     self.assertEqual(record.winner, match.away_team)
     self.assertEqual(record.loser, match.home_team)
     self.assertEqual(record.winner_rf, 5)
     self.assertEqual(record.winner_ra, 3)
     self.assertEqual(record.loser_ra, 5)
     self.assertEqual(record.loser_rf, 3)
コード例 #2
0
 def test_away_win(self):
     match = self.create_match()
     record = Result()
     record.match = match
     record.record_result(t1=match.home_team,
                          t2=match.away_team,
                          s1=3,
                          s2=5)
     self.assertEqual(record.winner, match.away_team)
     self.assertEqual(record.loser, match.home_team)
     self.assertEqual(record.winner_rf, 5)
     self.assertEqual(record.winner_ra, 3)
     self.assertEqual(record.loser_ra, 5)
     self.assertEqual(record.loser_rf, 3)
コード例 #3
0
    def start_round(self):
        if self.current_round <= self.max_round:
            # get the fixtures, find the round, assign the matches.
            fixtures = self.get_fixtures()
            if self.current_round < self.max_round:
                this_round = fixtures[self.current_round]
                for i in range(0, len(this_round), 2):
                    teams = this_round[i:i+2]
                    if not teams[0]:
                        teams[0] = teams[1]
                        teams[1] = None
                    match = Match.objects.create(home_team=teams[0], away_team=teams[1], group=self, round=self.current_round)
                    if not match.away_team:
                        result = Result()
                        result.match = match
                        result.record_result(t1=match.home_team, s1=3, is_bye=True)
                        result.save()
                        record = Record.objects.get(group=self, team=match.home_team)
                        record.record_match(rf=3, ra=0)

                self.current_round += 1
                self.save()

            else:  # all matches in this game have been played, set the group to finished and check if they are all finished at the div level
                self.is_finished = True
                self.save()
コード例 #4
0
 def test_bye(self):
     match = self.create_match()
     record = Result()
     record.match = match
     record.is_bye = True
     record.record_result(t1=match.home_team, s1=3, is_bye=True)
     record.save()
     self.assertEqual(record.is_bye, True)
     self.assertEqual(record.winner, match.home_team)
     self.assertEqual(record.loser, None)
     self.assertEqual(record.winner_rf, 3)
     self.assertEqual(record.winner_ra, 0)
コード例 #5
0
ファイル: tests.py プロジェクト: shdwpuppet/lanserver
 def test_bye(self):
     match = self.create_match()
     record = Result()
     record.match = match
     record.is_bye = True
     record.record_result(t1=match.home_team, s1=3, is_bye=True)
     record.save()
     self.assertEqual(record.is_bye, True)
     self.assertEqual(record.winner, match.home_team)
     self.assertEqual(record.loser, None)
     self.assertEqual(record.winner_rf, 3)
     self.assertEqual(record.winner_ra, 0)
コード例 #6
0
def match_setup(request, match_pk):
    match = get_object_or_404(Match, pk=match_pk)
    captains = match.home_team.get_captains() | match.away_team.get_captains()
    if request.user.player_set.all()[0] in captains or request.user.is_staff:
        print('passed test')
        context = {'match': match}
        map_pool = list(match.group.division.tournament.map_pool.all())
        [
            map_pool.remove(map) for map in map_pool
            if map in match.away_veto.all()
        ]
        [
            map_pool.remove(map) for map in map_pool
            if map in match.home_veto.all()
        ]
        context.update({'maps_remaining': map_pool})

        if len(match.home_veto.all()) == match.vetoes and len(
                match.away_veto.all()) == match.vetoes and not match.map:
            match.map = random.choice(map_pool)
            match.save()

        if not match.map:
            context.update({'phase': 'pick_map'})
            if match.veto_turn == 0:
                context.update({'picking_team': match.home_team})
            else:
                context.update({'picking_team': match.away_team})
        else:
            match.server = random.choice(
                Server.objects.filter(is_in_use=False))
            match.save()
            match.server.is_in_use = True
            match.server.save()
            pass
        if request.method == 'POST':
            result = Result()
            result.match = match
            result.record_result(t1=match.home_team,
                                 s1=request.POST.get('home_score'),
                                 t2=match.away_team,
                                 s2=request.POST.get('away_score'))
            result.save()
            match.server.is_in_use = False
            match.server.save()
            return redirect(detail, match_pk=match_pk)
        return render(request, 'match_setup.html', context)
    else:
        return redirect(detail, match_pk=match_pk)
コード例 #7
0
ファイル: views.py プロジェクト: shdwpuppet/lanserver
def match_setup(request, match_pk):
    match = get_object_or_404(Match, pk=match_pk)
    captains = match.home_team.get_captains() | match.away_team.get_captains()
    if request.user.player_set.all()[0] in captains or request.user.is_staff:
        print('passed test')
        context={'match': match}
        map_pool = list(match.group.division.tournament.map_pool.all())
        [map_pool.remove(map) for map in map_pool if map in match.away_veto.all()]
        [map_pool.remove(map) for map in map_pool if map in match.home_veto.all()]
        context.update({'maps_remaining': map_pool})

        if len(match.home_veto.all()) == match.vetoes and len(match.away_veto.all()) == match.vetoes and not match.map:
            match.map = random.choice(map_pool)
            match.save()

        if not match.map:
            context.update({'phase': 'pick_map'})
            if match.veto_turn == 0:
                context.update({'picking_team': match.home_team})
            else:
                context.update({'picking_team': match.away_team})
        else:
            match.server = random.choice(Server.objects.filter(is_in_use=False))
            match.save()
            match.server.is_in_use = True
            match.server.save()
            pass
        if request.method == 'POST':
            result = Result()
            result.match = match
            result.record_result(t1=match.home_team, s1=request.POST.get('home_score'), t2=match.away_team, s2=request.POST.get('away_score'))
            result.save()
            match.server.is_in_use = False
            match.server.save()
            return redirect(detail, match_pk=match_pk)
        return render(request, 'match_setup.html', context)
    else:
        return redirect(detail, match_pk=match_pk)