示例#1
0
def save_matches(queue):
    time.sleep(random.random())
    while not queue.empty():
        tokens = queue.get()
        if Team.objects.filter(name=tokens['home_team']).count() == 0:
            Team(name=tokens['home_team'], wins=0).save()
        if Team.objects.filter(name=tokens['away_team']).count() == 0:
            Team(name=tokens['away_team'], wins=0).save()

        team1_id = Team.objects.filter(
            name=tokens['home_team']).values('id')[0]['id']
        team2_id = Team.objects.filter(
            name=tokens['away_team']).values('id')[0]['id']
        team1 = Team.objects.filter(name=tokens['home_team'])[0]
        team2 = Team.objects.filter(name=tokens['away_team'])[0]
        if Match.objects.filter(Q(home_team=team1_id)
                                & Q(away_team=team2_id)).count() == 0:
            Match(home_team=team1,
                  away_team=team2,
                  home_score=tokens['first_match_home'],
                  away_score=tokens['first_match_away']).save()
        if Match.objects.filter(home_team=team2).filter(
                away_team=team1).count() == 0:
            Match(home_team=team2,
                  away_team=team1,
                  home_score=tokens['second_match_home'],
                  away_score=tokens['second_match_away']).save()

        winner_name = Match.get_winner(tokens)
        winner_team = Team.objects.get(name=winner_name)
        winner_team.wins += 1
        winner_team.save()
示例#2
0
文件: test_models.py 项目: Amoki/lc
	def test_leave_team_last(self):
		"""
		Set incative the team when nobody is here
		"""
		t = Team(name="haha", tag="ha", region=self.bre)
		t.save()
		TeamUser(team=t, summoner=self.s).save()
		self.s.leave_team(t)
		self.assertFalse(self.reload(t).active)
示例#3
0
文件: team.py 项目: ahangchen/WeMeet
def invite(name, leader, tel, mail):
    inv_code = str(random6())
    if Pwd.objects.filter(mail=mail).count() > 0:
        return None
    pwd = Pwd(mail=mail, invite_code=inv_code, state=1)
    pwd.save()
    team = Team(pwd=pwd, name=name, leader=leader, contact_tel=tel)
    team.save()
    return pwd.invite_code
示例#4
0
文件: test_models.py 项目: Amoki/lc
	def test_team_user_unicode(self):
		t0 = Team(name="team2", tag="OPSuperTeam", region=self.bre, manager=self.s)
		t0.save()
		tu_in = TeamUser(team=t0,
				summoner=self.s)
		tu_in.save()
		tu_out = TeamUser.objects.get(team=t0, summoner=self.s)
		tu_out.date_out = timezone.now()
		tu_out.save()
		self.assertEqual(str(tu_in), 'amoki is currently playing with [OPSuperTeam] team2')
		self.assertEqual(str(tu_out), 'amoki played with [OPSuperTeam] team2')
示例#5
0
def generate(using, count):
    for i in range(count):
        t = Team(name='team{}'.format(count), games=count, admin_id=1)
        t.save(using=using)
        for j in range(10):
            u = User.objects.get(username='******'.format(j + 10 * i))
            tu = UserTeam(
                user=u,
                team=t,
            )
            tu.save(using=using)
示例#6
0
class ModelTestCase(TestCase):
    def setUp(self):
        self.team_id = "1"
        self.team_name = "India"
        self.team_image = "India.png"
        self.team = Team(name=self.team_name, image=self.team_image)

    def test_model_can_create_a_team(self):
        """Test the game model can create a game."""
        old_count = Team.objects.count()
        self.team.save()
        new_count = Team.objects.count()
        self.assertNotEqual(old_count, new_count)
示例#7
0
文件: test_models.py 项目: Amoki/lc
	def test_team_request_unicode(self):
		tr_team = TeamRequest(team=self.t,
					summoner=self.s2,
					origin=TeamRequest.TEAM)
		tr_team.save()
		t0 = Team(name="team2", tag="OPSuperTeam", region=self.bre, manager=self.s)
		t0.save()
		tr_s = TeamRequest(team=t0,
					summoner=self.s,
					origin=TeamRequest.SUMMONER)
		tr_s.save()
		self.assertEqual(str(tr_team), '[OPTeam] team1 wants to add Telu to its roster')
		self.assertEqual(str(tr_s), 'amoki wants to join [OPSuperTeam] team2')
示例#8
0
 def get_teams(self):
     teams = self.stats.make_request(host="erikberg.com", sport='nba',
                                     method="teams", id=None,
                                     format="json",
                                     parameters={})
     for team in teams:
         try:
             team_obj = Team.objects.get(team_id=team['team_id'])
         except Team.DoesNotExist:
             team_obj = Team()
         for attr, value in team.items():
             setattr(team_obj, attr, value)
         team_obj.save()
示例#9
0
 def setUp(self):
     self.user = get_user_model()(username='******',
                                  email='*****@*****.**')
     self.user.save()
     self.team = Team(name='team-test',
                      password='******',
                      description='',
                      owner=self.user)
     self.team.save()
     self.user.team = self.team
     self.user.save()
     self.admin_user = get_user_model()(username='******',
                                        email='*****@*****.**')
     self.admin_user.is_staff = True
     self.admin_user.save()
示例#10
0
    def handle(self, *args, **options):

        team_objs = [
            Team(name="Team %s" % (i + 1), logo_file="team.jpg", club="Club Name")
            for i in range(self.no_of_teams)
        ]

        Team.objects.bulk_create(team_objs)

        teams = Team.objects.all()

        for team in teams:
            player_objs = [
                Player(
                    team=team,
                    first_name="Player",
                    last_name="%s" % (i + 1),
                    image_file="player.jpg",
                    jersey_number=random.randint(i * 5, (i * 5) + 5),
                    country="County Name",
                )
                for i in range(11)
            ]

            Player.objects.bulk_create(player_objs)
示例#11
0
 def setUp(self):
     user = get_user_model()(username='******',
                             email='*****@*****.**')
     user.save()
     admin_user = get_user_model()(
         username='******',
         email='*****@*****.**')
     admin_user.is_staff = True
     admin_user.save()
     team = Team(name='recalculate-team', owner=user, password='******')
     team.save()
     user.team = team
     user.save()
     self.user = user
     self.admin_user = admin_user
     self.team = team
示例#12
0
 def setUp(self):
     self.user = get_user_model()(
         username="******", email="*****@*****.**"
     )
     self.user.save()
     self.team = Team(
         name="team-test", password="******", description="", owner=self.user
     )
     self.team.save()
     self.user.team = self.team
     self.user.save()
     self.admin_user = get_user_model()(
         username="******", email="*****@*****.**"
     )
     self.admin_user.is_staff = True
     self.admin_user.save()
示例#13
0
文件: views.py 项目: DavidPage/gba
def populatedb(request):

    myTeams = ['Real Madrid', 'Barcelona']
    myCompetitions = ['La liga', 'English Premier League']
    myMarkets = ['Match Odds', 'Half Time']

    for market in myMarkets:
        try:
            Market.objects.get(market_name=market)
            print("Encontrado o market " + market)
        except ObjectDoesNotExist:
            print("A criar o market " + market)
            x = Market(market_name=market)
            x.save()

    for competition in myCompetitions:
        try:
            Competition.objects.get(competition_name=competition)
            print("Encontrada a competition " + competition)
        except ObjectDoesNotExist:
            print("A criar a competition " + competition)
            x = Competition(competition_name=competition)
            x.save()

    for team in myTeams:
        try:
            Team.objects.get(team_name=team)
            print("Encontrada a Team " + team)
        except ObjectDoesNotExist:
            print("A criar a team " + team)
            x = Team(team_name=team)
            x.save()

    return HttpResponseRedirect('/Trade/')
示例#14
0
    def create_first_user(cls, email="*****@*****.**", password="******"):
        if cls.query.filter_by().first():
            return None

        user = cls(email=email)
        user.password = password
        user_role = UserRole(role=Role.get_super_admin_role(), user=user)
        user.user_roles.append(user_role)

        db.session.add(user)
        db.session.commit()

        Team.create_team(name="Team0",
                         description="Default team",
                         creator_id=user.id)
        return True
示例#15
0
    def start(self):
        c = int(self.count / 10)

        for i in range(c):
            t1 = Team(
                name='team_{}'.format(i),
                games=self.count,
            )
            t2 = Team(
                name='team_{}'.format(i),
                games=self.count,
            )
            t1.save(using='db1')
            t2.save(using='db2')
            for j in range(10):
                u = User(username='******'.format(j + 10 * i),
                         email='ivan@ivan{}.ru'.format(j + 10 * i))
                u.set_password('ivan123')
                u.first_name = 'ivan{}'.format(j + 10 * i)
                u.last_name = 'ivanov{}'.format(j + 10 * i)
                ran_db = random.randint(1, 2)
                u.id = int(get_pk() + str(ran_db))
                print(u.id)
                u.save(using='db' + str(ran_db))
                if ran_db == 1:
                    tu = UserTeam(
                        user=u,
                        team=t1,
                    )
                else:
                    tu = UserTeam(
                        user=u,
                        team=t2,
                    )
                tu.save(using='db' + str(ran_db))
        cc = int(self.count / 100)

        for i in range(cc):
            t = Turn(name='turn{}'.format(i))
            t.save(using='db1')
            t.save(using='db2')
            for j in range(10):
                m = Match(name='match{}'.format(j + 10 * i), turn_id=t.id)
                m.save(using='db1')
                m.save(using='db2')
                for l in range(10):
                    g = Game(name='game___{}'.format(l + 10 * j + 100 * i),
                             match_id=m.id)
                    ran_db = random.randint(1, 2)
                    g.id = int(get_pk() + str(ran_db))
                    g.save(using='db' + str(ran_db))
                    tm = Team.objects.using('db' + str(ran_db)).filter(
                        name='team_{}'.format(j + 10 * i))[0]
                    gt = GameTeam(game=g, team=tm)
                    gt.save(using='db' + str(ran_db))
示例#16
0
文件: tests.py 项目: rtm516/core
 def setUp(self):
     user = get_user_model()(
         username="******", email="*****@*****.**"
     )
     user.save()
     admin_user = get_user_model()(
         username="******",
         email="*****@*****.**",
     )
     admin_user.is_staff = True
     admin_user.save()
     team = Team(name="recalculate-team", owner=user, password="******")
     team.save()
     user.team = team
     user.save()
     self.user = user
     self.admin_user = admin_user
     self.team = team
示例#17
0
文件: test_models.py 项目: Amoki/lc
	def test_is_manager_of(self):
		t = Team(name="haha", tag="ha", region=self.bre, manager=self.s)
		t.save()
		TeamUser(team=t, summoner=self.s).save()
		self.assertTrue(self.s.is_manager_of(t))
		t.manager = self.s2
		t.save()
		self.assertFalse(self.s.is_manager_of(t))
示例#18
0
def index(request):
    if request.method == 'POST':
        if 'delete' in request.POST:
            team_list = Team.objects.all().order_by('-team_name')
            delete_team = team_list.get(pk=request.POST['delete-team'])
            delete_team.delete()
            team_list = Team.objects.all().order_by('-team_name')
            new_form = AddTeamForm()
            dictionary = {'team_list': team_list, 'form': new_form}
            render(request, 'team/index.html', dictionary)
        else:
            form = AddTeamForm(request.POST)
            if form.is_valid():
                new_team = Team()
                new_team.team_name = form.cleaned_data['team_name']
                new_team.save()
                team_list = Team.objects.all().order_by('-team_name')
                new_form = AddTeamForm()
                dictionary = {'team_list': team_list, 'form': new_form}
                render(request, 'team/index.html', dictionary)
    form = AddTeamForm()
    team_list = Team.objects.all().order_by('-team_name')
    context = {'team_list': team_list, 'form': form}
    return render(request, 'team/index.html', context)
示例#19
0
def createteam():
    for i in range(0, len(TEAM)):
        Team().create_team(name=TEAM[i])
        print("Team %s created successfully" % TEAM[i])
        for j in range(0, 11):
            name = "player_%s_%s" % (j, TEAM[i])
            coach = False
            height = float(randrange(60, 70) / 10)
            score = 0
            if j == 0:
                name = "coach_%s_%s" % (j, TEAM[i])
                coach = True
                score = None
            Players().create_players(team=TEAM[i], name=name, coach=coach, height=height,
                                     score=score)
        print("Players created successfully")
示例#20
0
def create_team(request, is_commissioner=0, league_id=''):
    global errors
    league_id = request.POST.get('leagueId', league_id)
    team_name = request.POST.get('teamName', '')
    password = request.POST.get('entryKey', '')
    errors = []
    if not (league_id and team_name):
        errors.append("<br/> League id and/or team_name is none!")
        return None

    l = League.objects.get(league_id=league_id)
    teams = l.team_set.all()
    user = request.user

    if (not is_commissioner) and (l.password) and (password != l.password):
        errors.append("<br/> - Password did not match!")
    if l.settings.number_of_teams <= len(teams):
        errors.append("<br/> - league is already full!")
        print errors, l.settings.number_of_teams, teams
    if user in [t.user for t in teams]:
        errors.append(
            "<br/> - you (%s) already have a team in this league! click inside the league to know about it."
            % request.user)
        print errors, user, [t.user for t in teams]
    if errors:
        return None

    vendor_team_id = generate_random_id(4)
    vendor_user_id = 'xxyyzz'
    waiver_priority = 1
    division = ''
    draft_pick_number = get_draft_pick_number(l)
    t = Team(league=l,
             user=user,
             vendor_team_id=vendor_team_id,
             vendor_user_id=vendor_user_id,
             team_name=team_name,
             waiver_priority=waiver_priority,
             division=division,
             is_commissioner=is_commissioner,
             draft_pick_number=draft_pick_number)
    return t
示例#21
0
def populate():
    for i in range(15):
        user = get_user_model()(username=f'scorelist-test{i}',
                                email=f'scorelist-test{i}@example.org')
        user.save()
        team = Team(name=f'scorelist-test{i}',
                    password=f'scorelist-test{i}',
                    owner=user)
        team.points = i * 100
        team.leaderboard_points = i * 100
        team.save()
        user.team = team
        user.points = i * 100
        user.leaderboard_points = i * 100
        user.save()
        Score(team=team, user=user, reason='test', points=i * 100).save()
示例#22
0
    def deactivate_team(self, test_client, current_user_role, should_be_successful=True):
        login(test_client, self.user_data[current_user_role])

        self.assertEqual(eval(f"current_user.is_{current_user_role}"), True)
        team = get_current_user_random_team()
        team_is_active = team.is_active
        team_name = team.name
        response = view_teams_list(test_client)

        if should_be_successful:
            self.assertIn("ctivate", str(response.data))
            for click in range(2):
                toggle_team_status(test_client, team_name)
                updated_team = Team.get_team_by_name(team_name)

                if click % 2:
                    self.assertEqual(team_is_active, updated_team.is_active)
                else:
                    self.assertNotEqual(team_is_active, updated_team.is_active)
        else:
            self.assertNotIn('ctivate', str(response.data))
        logout(test_client)
示例#23
0
    def start(self):
        c = int(self.count / 10)

        for i in range(c):
            t = Team(
                name='team{}'.format(i),
                games=self.count,
            )
            t.save(using=self.using)
            for j in range(10):
                u = User(username='******'.format(j + 10 * i),
                         email='ivan@ivan{}.ru'.format(j + 10 * i))
                u.set_password('ivan123')
                u.first_name = 'ivan{}'.format(j + 10 * i)
                u.last_name = 'ivanon{}'.format(j + 10 * i)
                u.save(using=self.using)
                tu = UserTeam(
                    user=u,
                    team=t,
                )
                tu.save(using=self.using)
        cc = int(self.count / 100)

        for i in range(cc):
            t = Turn(name='turn{}'.format(i))
            t.save(using=self.using)
            for j in range(10):
                m = Match(name='match{}'.format(j + 10 * i), turn_id=t.id)
                m.save(using=self.using)
                for l in range(10):
                    g = Game(name='game{}'.format(l + 10 * j + 100 * i),
                             match_id=m.id)
                    g.save(using=self.using)
                    tm = Team.objects.using(
                        self.using).get(name='team{}'.format(j + 10 * i))
                    print(g.name, t.name)
                    gt = GameTeam(game=g, team=tm)
                    gt.save(using=self.using)
示例#24
0
 def create(self, name: str, description: str) -> Team:
     team = Team(name=name, description=description)
     team.save()
     return team
示例#25
0
文件: test_models.py 项目: Amoki/lc
	def test_leave_team_manager_no_last(self):
		t = Team(name="haha", tag="ha", region=self.bre, manager=self.s)
		t.save()
		TeamUser(team=t, summoner=self.s).save()
		TeamUser(team=t, summoner=self.s2).save()
		self.assertRaises(IntegrityError, lambda: self.s.leave_team(t))
示例#26
0
 def setUp(self):
     self.team_id = "1"
     self.team_name = "India"
     self.team_image = "India.png"
     self.team = Team(name=self.team_name, image=self.team_image)
    def handle(self, *args, **options):
        print('Creating 10 categories...')
        for i in range(10):
            category = Category(name='category-' + str(i), display_order=i, contained_type='test',
                                description='Category ' + str(i))
            category.save()

        print('Creating 100 challenges for each category...')
        for i in range(10):
            category = Category.objects.get(name='category-' + str(i))
            for j in range(50):
                challenge = Challenge(name='cat-' + str(i) + '-chal-' + str(j), category=category,
                                      description='An example challenge ' + str(j),
                                      flag_metadata={'flag': f'ractf{{{j}}}'}, author='dave', auto_unlock=True, score=j,
                                      challenge_metadata={})
                challenge.save()
            for j in range(50, 100, 2):
                challenge = Challenge(name='cat-' + str(i) + '-chal-' + str(j), category=category,
                                      description='An example challenge ' + str(j),
                                      flag_metadata={'flag': f'ractf{{{j}}}'}, author='dave', auto_unlock=True,
                                      score=j, challenge_metadata={})
                challenge2 = Challenge(name='cat-' + str(i) + '-chal-' + str(j + 1), category=category,
                                       description='An example challenge ' + str(j + 1),
                                       flag_metadata={'flag': f'ractf{{{j + 1}}}'}, author='dave', auto_unlock=False,
                                       score=j, challenge_metadata={})
                challenge2.save()
                challenge.save()
                challenge.unlocks.add(challenge2)

        print('Creating 20000 users with 10000 teams with 100 solves per team...')
        for i in range(10000):
            user = get_user_model()(username='******' + str(i), email='user-' + str(i) + '@example.org')
            user.save()
            team = Team(name='team-' + str(i), password='******', owner=user)
            team.save()
            user2 = get_user_model()(username='******' + str(i) + '-second', email='user-' + str(i) + '*****@*****.**',
                                     team=team)
            user2.save()
            for j in range(50):
                challenge = Category.objects.get(name='category-' + str(j % 5))\
                    .category_challenges.get(name='cat-' + str(j % 5) + '-chal-' + str(j))
                points = random.randint(0, 1000)
                score = Score(team=team, reason='challenge', points=points, penalty=0, leaderboard=True)
                score.save()
                solve = Solve(team=team, solved_by=user, challenge=challenge, first_blood=challenge.first_blood is None,
                              flag='ractf{}', score=score, correct=True)
                solve.save()
                user.points += points
                team.points += points
                user.leaderboard_points += points
                team.leaderboard_points += points
            for j in range(50):
                challenge = Category.objects.get(name='category-' + str(j % 5 + 5))\
                    .category_challenges.get(name='cat-' + str(j % 5 + 5) + '-chal-' + str(j))
                points = random.randint(0, 1000)
                score = Score(team=team, reason='challenge', points=points, penalty=0, leaderboard=True)
                score.save()
                solve = Solve(team=team, solved_by=user2, challenge=challenge,
                              first_blood=challenge.first_blood is None, flag='ractf{}', score=score, correct=True)
                solve.save()
                user2.points += points
                team.points += points
                user.leaderboard_points += points
                team.leaderboard_points += points
示例#28
0
 def setUp(self):
     category = Category(name='test',
                         display_order=0,
                         contained_type='test',
                         description='')
     category.save()
     challenge1 = Challenge(name='test1',
                            category=category,
                            description='a',
                            challenge_type='basic',
                            challenge_metadata={},
                            flag_type='plaintext',
                            flag_metadata={'flag': 'ractf{a}'},
                            author='dave',
                            score=1000)
     challenge2 = Challenge(name='test2',
                            category=category,
                            description='a',
                            challenge_type='basic',
                            challenge_metadata={},
                            flag_type='plaintext',
                            flag_metadata={'flag': 'ractf{a}'},
                            author='dave',
                            score=1000,
                            auto_unlock=True)
     challenge3 = Challenge(name='test3',
                            category=category,
                            description='a',
                            challenge_type='basic',
                            challenge_metadata={},
                            flag_type='plaintext',
                            flag_metadata={'flag': 'ractf{a}'},
                            author='dave',
                            score=1000,
                            auto_unlock=False)
     challenge1.save()
     challenge2.save()
     challenge3.save()
     challenge2.unlocks.add(challenge1)
     challenge2.save()
     hint1 = Hint(name='hint1', challenge=challenge1, text='a', penalty=100)
     hint2 = Hint(name='hint2', challenge=challenge1, text='a', penalty=100)
     hint3 = Hint(name='hint3', challenge=challenge2, text='a', penalty=100)
     hint1.save()
     hint2.save()
     hint3.save()
     user = get_user_model()(username='******',
                             email='*****@*****.**')
     user.save()
     team = Team(name='team', password='******', owner=user)
     team.save()
     user.team = team
     user.save()
     user2 = get_user_model()(username='******',
                              email='*****@*****.**')
     user2.team = team
     user2.save()
     user3 = get_user_model()(username='******',
                              email='*****@*****.**')
     user3.save()
     team2 = Team(name='team2', password='******', owner=user3)
     team2.save()
     user3.team = team2
     user3.save()
     self.user = user
     self.user2 = user2
     self.user3 = user3
     self.team = team
     self.team2 = team2
     self.category = category
     self.challenge1 = challenge1
     self.challenge2 = challenge2
     self.challenge3 = challenge3
     self.hint1 = hint1
     self.hint2 = hint2
     self.hint3 = hint3
示例#29
0
文件: views.py 项目: DavidPage/Django
def insert(request):
    if request.method == 'POST': # If the form has been submitted...
        t = Team(team_name=request.POST["teamName"])
        t.save()
        return HttpResponseRedirect('/Team/')
示例#30
0
文件: models.py 项目: Amoki/lc
	def create_team(self, name, tag):
		new_team = Team(name=name, tag=tag, region=self.region, manager=self)
		new_team.save()
		TeamUser(team=new_team, summoner=self).save()
		return new_team
示例#31
0
 def test_create_team(self):
     team = mixer.blend(Team)
     Team().create_team(name=team.name)
     new_Team = Team.objects.filter(name=team.name).first()
     assert new_Team.name == team.name