本文整理汇总了Python中models.Match.tournament方法的典型用法代码示例。如果您正苦于以下问题:Python Match.tournament方法的具体用法?Python Match.tournament怎么用?Python Match.tournament使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Match
的用法示例。
在下文中一共展示了Match.tournament方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: confirm_match
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import tournament [as 别名]
def confirm_match(request, req_id=None):
if request.method == "POST":
if req_id is not None:
try:
sr = ScoreRequest.objects.get(id=req_id)
except:
return HttpResponseRedirect('/welcome/')
form = ConfirmRequestForm(request.POST, instance=sr)
print form
if form.is_valid() and sr.player2.user.username == request.user.username: #and needs to verify player2 is current player lol
form.save()
if int(request.POST['verified']) == 2:
#Save fields into a Match object now
match = Match()
match.player1 = sr.player1
match.player2 = sr.player2
match.wins = sr.wins
match.loss = sr.loss
match.ties = sr.ties
match.tournament = sr.tournament
match.save()
return HttpResponseRedirect('/welcome/')
return HttpResponseRedirect('/welcome/')
else:
print "Only POST requests for now"
return HttpResponseRedirect('/welcome/')
示例2: start_tournament
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import tournament [as 别名]
def start_tournament(tournament_id):
"""
Starts a tournament
:param tournament_id: Id of a tournament to start
:return: True if success, False otherwise
"""
try:
the_tournament = Tournament.objects.get(id=tournament_id)
t_users = [x.user for x in Registration.objects.filter(tournament=the_tournament)]
except ObjectDoesNotExist:
return False
if len(t_users) < the_tournament.max_participants:
## Add free slots
pass
for i in range(the_tournament.max_participants - 1):
m = Match()
m.tournament = the_tournament
m.code = i
if i < the_tournament.max_participants / 2:
m.left_user = t_users[i * 2]
m.right_user = t_users[i * 2 + 1]
m.save()
# Let the game begin!
the_tournament.has_started = True
the_tournament.save()
for reg in Registration.objects.filter(tournament=the_tournament):
reg.delete()
return True
示例3: start_tournament
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import tournament [as 别名]
def start_tournament(self, request, queryset):
# For each tournament that we are starting...
for tournament in queryset:
# Grab all of the teams that are in a specific tournament
teams_q = Team.objects.filter(tournaments__id=tournament.id)
teams = []
for tq in teams_q:
teams.append(tq)
# Randomize the teams!
random.shuffle(teams)
round_num = 1
# Create initial matches
team_offset = 0
while (len(teams) - team_offset) > 0:
# If we have enough teams for a match...
if (len(teams) - team_offset) >= tournament.teams_per_match:
# Create a match
match = Match()
match.round = round_num
match.tournament = tournament
# Sync back to the DB before adding teams
match.save()
match.teams
for _ in xrange(tournament.teams_per_match):
#while len(match.teams) < tournament.teams_per_match:
match.teams.add(teams[team_offset])
team_offset += 1
match.save()
else:
# Since we have teams left, but not enough for a match
# We create dud matches with seed teams
match = Match()
match.round = round_num
match.tournament = tournament
match.save()
if teams[team_offset]:
match.teams.add(teams[team_offset])
match.teams.winner = teams[team_offset]
team_offset += 1
# Create each round's tournaments
done = False
while not done:
matches = Match.objects.filter(round_num=round_num, tournament=tournament.id)
if len(matches) > 0:
round_num += 1
new_matches = (len(matches) / tournament.teams_per_match)
new_seeds = (len(matches) % tournament.teams_per_match)
if new_matches == 1 and new_seeds == 0:
done = True
old_matches = []
for match in matches:
old_matches.append(match)
for _ in xrange(new_matches):
new_match = Match()
new_match.round = round_num
new_match.tournament = tournament
new_match.save()
for _ in xrange(tournament.teams_per_match):
t_match = old_matches.pop()
t_match.child = new_match
t_match.save()
while new_seeds >= tournament.teams_per_match:
new_match = Match()
new_match.round = round_num
new_match.tournament = tournament
new_match.save()
for _ in xrange(tournament.teams_per_match):
t_match = old_matches.pop()
t_match.child = new_match
t_match.save()
new_seeds -= tournament.teams_per_match
for _ in xrange(new_seeds):
new_match = Match()
new_match.round = round_num
new_match.tournament = tournament
new_match.save()
t_match = old_matches.pop()
t_match.child = new_match
new_match.save()
t_match.save()
else:
done = True