@@ -528,4 +528,65 @@ def launch_group_matchs_action(self,request,queryset):
528
528
self .message_user (request ,_ ("Les matchs ont bien été lancés" ))
529
529
530
530
531
- admin .site .register (GroupMatch , GroupMatchAdmin )
531
+ admin .site .register (GroupMatch , GroupMatchAdmin )
532
+
533
+
534
+ class BracketAdmin (admin .ModelAdmin ):
535
+ """Admin handle for Brackets"""
536
+
537
+ list_display = ("id" , "name" , "tournament" )
538
+ search_fields = ["name" ,"tournament" ,"tournament__event" ,"tournament__game" ]
539
+ actions = ["create_empty_knockout_matchs_action" ,"fill_knockout_matchs_action" ]
540
+
541
+ list_filter = ["tournament" ,"tournament__event" ]
542
+
543
+ @admin .action (description = _ ("Créer les matchs" ))
544
+ def create_empty_knockout_matchs_action (self ,request ,queryset ):
545
+ for bracket in queryset :
546
+ if any ([MatchStatus .SCHEDULED != m .status for m in KnockoutMatch .objects .filter (bracket = bracket )]):
547
+ self .message_user (request ,_ ("Des matchs existent déjà et sont en cours ou terminés" ))
548
+
549
+ create_empty_knockout_matchs (bracket )
550
+ self .message_user (request ,_ ("Matchs créer avec succès" ))
551
+
552
+ @admin .action (description = _ ("Remplir les matchs" ))
553
+ def fill_knockout_matchs_action (self ,request ,queryset ):
554
+ for bracket in queryset :
555
+ # fill_knockout_matchs(bracket)
556
+ pass
557
+
558
+ admin .site .register (Bracket , BracketAdmin )
559
+
560
+ class KnockoutMatchAdmin (admin .ModelAdmin ):
561
+ """Admin handle for Knockout matchs"""
562
+
563
+ list_display = ("id" , "bracket" , "status" )
564
+ filter_horizontal = ("teams" ,)
565
+ actions = ["" ]
566
+
567
+ list_filter = ["bracket" , "bracket__tournament" , "round_number" , "index_in_round" ]
568
+
569
+ @admin .action (description = _ ("Lancer les matchs" ))
570
+ def launch_knockout_matchs_action (self ,request ,queryset ):
571
+ for match in queryset :
572
+ for team in match .get_teams ():
573
+ team_matchs = KnockoutMatch .objects .filter (teams = team ,round_index__gt = match .round_number )
574
+ for team_match in team_matchs :
575
+ if team_match .status == MatchStatus .ONGOING :
576
+ self .message_user (request ,_ (f"L'équipe { team .name } est encore dans un match en cours" ), messages .ERROR )
577
+ return
578
+ if team_match .status == MatchStatus .SCHEDULED :
579
+ 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 )
580
+ return
581
+
582
+ if len (match .get_teams ()) == 1 :
583
+ match .status = MatchStatus .COMPLETED
584
+ # score
585
+ else :
586
+ match .status = MatchStatus .ONGOING
587
+
588
+ match .save ()
589
+ self .message_user (request ,_ ("Les matchs ont bien été lancés" ))
590
+
591
+
592
+ admin .site .register (KnockoutMatch , KnockoutMatchAdmin )
0 commit comments