|
|
|
|
@ -70,46 +70,63 @@ class Tournament(models.Model): |
|
|
|
|
summons.sort(key=lambda s: s.weight) |
|
|
|
|
return summons |
|
|
|
|
|
|
|
|
|
def live_matches(self, broadcasted, group_stage_id, round_id): |
|
|
|
|
def match_groups(self, broadcasted, group_stage_id, round_id): |
|
|
|
|
|
|
|
|
|
matches = [] |
|
|
|
|
match_groups = [] |
|
|
|
|
if group_stage_id: |
|
|
|
|
matches = self.group_stage_matches(group_stage_id) |
|
|
|
|
group_stage = self.groupstage_set.filter(id=group_stage_id).first() |
|
|
|
|
match_groups.append(self.group_stage_match_group(group_stage, broadcasted)) |
|
|
|
|
elif round_id: |
|
|
|
|
matches = self.round_matches(round_id) |
|
|
|
|
round = self.round_set.filter(id=round_id).first() |
|
|
|
|
match_groups = self.round_match_groups(round, broadcasted) |
|
|
|
|
else: |
|
|
|
|
matches = self.all_matches() |
|
|
|
|
match_groups = self.all_groups(broadcasted) |
|
|
|
|
|
|
|
|
|
# matches = [m for m in matches if m.broadcasted==True] |
|
|
|
|
if not broadcasted: |
|
|
|
|
matches = [m for m in matches if len(m.team_scores.all()) > 0] |
|
|
|
|
|
|
|
|
|
matches.sort(key=lambda m: m.order) |
|
|
|
|
return match_groups |
|
|
|
|
|
|
|
|
|
return [match.live_match() for match in matches] |
|
|
|
|
# return map(lambda match: match.live_match(), matches) |
|
|
|
|
|
|
|
|
|
def all_matches(self): |
|
|
|
|
matches = [] |
|
|
|
|
def all_groups(self, broadcasted): |
|
|
|
|
groups = [] |
|
|
|
|
for group_stage in self.groupstage_set.all(): |
|
|
|
|
for match in group_stage.match_set.all(): |
|
|
|
|
matches.append(match) |
|
|
|
|
group = self.group_stage_match_group(group_stage, broadcasted) |
|
|
|
|
groups.append(group) |
|
|
|
|
for round in self.round_set.all(): |
|
|
|
|
for match in round.match_set.all(): |
|
|
|
|
matches.append(match) |
|
|
|
|
return matches |
|
|
|
|
groups = self.round_match_groups(round, broadcasted) |
|
|
|
|
return groups |
|
|
|
|
|
|
|
|
|
def group_stage_match_group(self, group_stage, broadcasted): |
|
|
|
|
return self.create_match_group(group_stage.name(), group_stage.match_set.all(), broadcasted) |
|
|
|
|
|
|
|
|
|
def group_stage_matches(self, group_stage_id): |
|
|
|
|
group_stage = self.groupstage_set.filter(id=group_stage_id).first() |
|
|
|
|
return group_stage.match_set.all() |
|
|
|
|
def round_match_groups(self, round, broadcasted): |
|
|
|
|
groups = [] |
|
|
|
|
group = self.create_match_group(round.name(), round.match_set.all(), broadcasted) |
|
|
|
|
groups.append(group) |
|
|
|
|
for child in round.children.all(): |
|
|
|
|
children_groups = self.round_match_groups(child, broadcasted) |
|
|
|
|
groups.extend(children_groups) |
|
|
|
|
|
|
|
|
|
def round_matches(self, round_id): |
|
|
|
|
round = self.round_set.filter(id=round_id).first() |
|
|
|
|
return round.match_set.all() |
|
|
|
|
return groups |
|
|
|
|
|
|
|
|
|
def create_match_group(self, name, matches, broadcasted): |
|
|
|
|
if not broadcasted: |
|
|
|
|
matches = [m for m in matches if len(m.team_scores.all()) > 0] |
|
|
|
|
matches.sort(key=lambda m: m.order) |
|
|
|
|
live_matches = [match.live_match() for match in matches] |
|
|
|
|
return MatchGroup(name, live_matches) |
|
|
|
|
|
|
|
|
|
def live_group_stages(self): |
|
|
|
|
return [gs.live_group_stages() for gs in self.groupstage_set.all()] |
|
|
|
|
|
|
|
|
|
class MatchGroup: |
|
|
|
|
def __init__(self, name, matches): |
|
|
|
|
self.name = name |
|
|
|
|
self.matches = matches |
|
|
|
|
|
|
|
|
|
def add_match(self, match): |
|
|
|
|
self.matches.append(match) |
|
|
|
|
|
|
|
|
|
def add_matches(self, matches): |
|
|
|
|
self.matches = matches |
|
|
|
|
|
|
|
|
|
class TeamSummon: |
|
|
|
|
def __init__(self, names, date, weight, stage, image): |
|
|
|
|
self.names = names |
|
|
|
|
|