Skip to content

Commit a143e03

Browse files
committed
add better error message on group matchs launch action
1 parent 6a1478e commit a143e03

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

insalan/tournament/admin.py

+18-10
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from django.utils.decorators import method_decorator
2727

2828
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
3030

3131
sensitive_post_parameters_m = method_decorator(sensitive_post_parameters())
3232

@@ -504,26 +504,34 @@ def create_group_matchs_action(self,request,queryset):
504504

505505

506506
class GroupMatchAdmin(admin.ModelAdmin):
507-
"""Admin handlet for group matchs"""
507+
"""Admin handle for group matchs"""
508508

509-
list_display = ("id", "status", "group")
509+
list_display = ("id", "group", "status")
510510
search_fields = ["index_in_round","round_number"]
511511
filter_horizontal = ("teams",)
512512
actions = ["launch_group_matchs_action"]
513513

514-
list_filter = ["group","group__tournament","round_number"]
514+
list_filter = ["group","group__tournament","round_number","index_in_round"]
515515

516516
@admin.action(description=_("Lancer les matchs"))
517517
def launch_group_matchs_action(self,request,queryset):
518518
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:
523523
self.message_user(request,_(f"L'équipe {team.name} est encore dans un match en cours"), messages.ERROR)
524524
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+
527535
match.save()
528536
self.message_user(request,_("Les matchs ont bien été lancés"))
529537

0 commit comments

Comments
 (0)