Esempio n. 1
0
    def post(self, request, league_slug):
        if not request.user.is_anonymous():
            active_user_id = request.user.id
            active_user = User.objects.filter(id=active_user_id)[0]
            current_league = League.objects.filter(slug=league_slug)[0]
            submitted_form = TeamForm(request.POST)
            if submitted_form.is_valid:
                name = submitted_form.data.get('name')

                if not Team.objects.filter(manager=active_user, league=current_league):

                    if not Team.objects.filter(name=name, league=current_league):

                        if submitted_form.files.get('mascot'):
                            mascot = submitted_form.files.get('mascot')
                            new_league_team = Team(name = name, manager = active_user, league = current_league, mascot=mascot)
                        else:
                            new_league_team = Team(name = name, manager = active_user, league = current_league)

                        new_league_team.slug = slugify(new_league_team.name)
                        new_league_team.save()

                        return redirect('interface:team_view', league_slug = current_league.slug, team_slug = new_league_team.slug)
                return redirect('interface:create_team', league_slug = current_league.slug)
        return redirect('interface:index')
Esempio n. 2
0
    def setUpTestData(cls):
        super().setUpTestData()
        for i in range(4):
            User.objects.create_user(username='******' + str(i),
                                     email='player' + str(i) + '@test.com',
                                     password=cls.password)
        players = Player.objects.all()
        players_team_a = [players[0], players[1]]
        players_team_b = [players[2], players[3]]
        team_a = Team.create(players_team_a)
        team_b = Team.create(players_team_b)
        print(team_a)
        print(team_b)

        team_a = Team.get_or_create_team(
            [player.id for player in team_a.players.all()])
        team_b = Team.get_or_create_team(
            [player.id for player in team_b.players.all()])
        teams = [team_a, team_b]
        max_score = 13
        score_a = 13
        score_b = 7
        game = Game.create(max_score=max_score, teams=teams)
        ScoreTeam.objects.create(team=team_a, game=game, score=score_a)
        ScoreTeam.objects.create(team=team_b, game=game, score=score_b)
        max_score = 13
        score_a = 7
        score_b = 13
        game = Game.create(max_score=max_score, teams=teams)
        ScoreTeam.objects.create(team=team_a, game=game, score=score_a)
        ScoreTeam.objects.create(team=team_b, game=game, score=score_b)
Esempio n. 3
0
 def setUpTestData(cls):
     super().setUpTestData()
     for i in range(4):
         User.objects.create_user(username='******' + str(i),
                                  email='player' + str(i) + '@test.com',
                                  password=cls.password)
     players = Player.objects.all()
     players_team_a = [players[0], players[1]]
     players_team_b = [players[2], players[3]]
     team_a = Team.create(players_team_a)
     team_b = Team.create(players_team_b)
     print(team_a)
     print(team_b)
Esempio n. 4
0
 def create(self, request, *args, **kwargs):
     print(request.data)
     max_score = request.data['maxScore']
     players_team_a = request.data['playersTeamA']
     players_team_b = request.data['playersTeamB']
     score_a = request.data['scoreTeamA']
     score_b = request.data['scoreTeamB']
     players_team_a_ids = [player["id"] for player in players_team_a]
     players_team_b_ids = [player["id"] for player in players_team_b]
     team_a = Team.get_or_create_team(players_team_a_ids)
     team_b = Team.get_or_create_team(players_team_b_ids)
     teams = [team_a, team_b]
     game = Game.create(max_score=max_score, teams=teams)
     ScoreTeam.objects.create(team=team_a, game=game, score=score_a)
     ScoreTeam.objects.create(team=team_b, game=game, score=score_b)
     print(game)
     self.kwargs['pk'] = game.id
     return self.retrieve(request)
 def create_game(game_data):
     game = Game.objects.create(max_score=game_data['max_score'])
     for score in game_data['scores']:
         team_players_ids = []
         for name in score['players']:
             team_players_ids.append(Player.get_by_name(name).id)
         team = Team.get_or_create_team(team_players_ids)
         game.teams.add(team)
         ScoreTeam.objects.create(team=team,
                                  game=game,
                                  score=score['score'])
     game.save()
     return game
Esempio n. 6
0
    def post(self, request, league_slug):
        if request.session.get('_auth_user_id'):

            active_user_id = int(request.session.get('_auth_user_id'))
            active_user = User.objects.filter(id=active_user_id)[0]

            current_league = League.objects.filter(slug=league_slug)[0]

            name = request.POST['name']

            if not Team.objects.filter(manager=active_user, league=current_league):

                if not Team.objects.filter(name=name, league=current_league):

                    new_league_team = Team(name = name, manager = active_user, league = current_league)

                    new_league_team.slug = slugify(new_league_team.name)
                    new_league_team.save()

                    new_league_team_dict = new_league_team.to_json()

                    return JsonResponse({'Success':True, 'new_league_team_dict': new_league_team_dict})
                return JsonResponse({'Success':False, 'Error':'Team name already taken in this league.'})
            return JsonResponse({'Success':False, 'Error':'Limit one team per manager per league.'})
Esempio n. 7
0
 def populate_teams(self, faker: Faker):
     for i in range(16):
         team = Team(name=faker.name())
         team.save()
     msg.good("Teams data successfully populated")