|
26 | 26 | from django.utils.decorators import method_decorator
|
27 | 27 |
|
28 | 28 | from .models import Event, Tournament, Game, Team, Player, Manager, Substitute, Caster, PaymentStatus, Group, GroupMatch, KnockoutMatch, Bracket, Seeding, MatchStatus
|
29 |
| -from insalan.tournament.manage import create_group_matchs |
| 29 | +from insalan.tournament.manage import create_group_matchs, create_empty_knockout_matchs |
30 | 30 |
|
31 | 31 | sensitive_post_parameters_m = method_decorator(sensitive_post_parameters())
|
32 | 32 |
|
@@ -504,26 +504,34 @@ def create_group_matchs_action(self,request,queryset):
|
504 | 504 |
|
505 | 505 |
|
506 | 506 | class GroupMatchAdmin(admin.ModelAdmin):
|
507 |
| - """Admin handlet for group matchs""" |
| 507 | + """Admin handle for group matchs""" |
508 | 508 |
|
509 |
| - list_display = ("id", "status", "group") |
| 509 | + list_display = ("id", "group", "status") |
510 | 510 | search_fields = ["index_in_round","round_number"]
|
511 | 511 | filter_horizontal = ("teams",)
|
512 | 512 | actions = ["launch_group_matchs_action"]
|
513 | 513 |
|
514 |
| - list_filter = ["group","group__tournament","round_number"] |
| 514 | + list_filter = ["group","group__tournament","round_number","index_in_round"] |
515 | 515 |
|
516 | 516 | @admin.action(description=_("Lancer les matchs"))
|
517 | 517 | def launch_group_matchs_action(self,request,queryset):
|
518 | 518 | for match in queryset:
|
519 |
| - for team in match.teams.all(): |
520 |
| - team_matchs = GroupMatch.objects.filter(teams=team) |
521 |
| - for team_math in team_matchs: |
522 |
| - if team_math.status == MatchStatus.ONGOING: |
| 519 | + for team in match.get_teams(): |
| 520 | + team_matchs = GroupMatch.objects.filter(teams=team,round_number__lt=match.round_number) |
| 521 | + for team_match in team_matchs: |
| 522 | + if team_match.status == MatchStatus.ONGOING: |
523 | 523 | self.message_user(request,_(f"L'équipe {team.name} est encore dans un match en cours"), messages.ERROR)
|
524 | 524 | return
|
525 |
| - |
526 |
| - match.status = MatchStatus.ONGOING |
| 525 | + if team_match.status == MatchStatus.SCHEDULED: |
| 526 | + self.message_user(request,_(f"L'équipe {team.name} n'a pas encore joué un ou des matchs des rounds précédent"), messages.ERROR) |
| 527 | + return |
| 528 | + |
| 529 | + if len(match.get_teams()) == 1: |
| 530 | + match.status = MatchStatus.COMPLETED |
| 531 | + # score de la team à changer |
| 532 | + else: |
| 533 | + match.status = MatchStatus.ONGOING |
| 534 | + |
527 | 535 | match.save()
|
528 | 536 | self.message_user(request,_("Les matchs ont bien été lancés"))
|
529 | 537 |
|
|
0 commit comments