mirror of
https://github.com/AudebertAdrien/ft_transcendence.git
synced 2025-12-17 22:47:49 +01:00
FIXED git add .git add . need to be clean
This commit is contained in:
parent
e8f46e211c
commit
c8bcf87117
@ -9,8 +9,6 @@ from asgiref.sync import sync_to_async
|
|||||||
from .models import Tournoi
|
from .models import Tournoi
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
|
||||||
executor = ThreadPoolExecutor(max_workers=5)
|
|
||||||
lock = asyncio.Lock()
|
|
||||||
class Game:
|
class Game:
|
||||||
# Global variable to handle the using of the database
|
# Global variable to handle the using of the database
|
||||||
USING_DB = False
|
USING_DB = False
|
||||||
@ -59,14 +57,18 @@ class Game:
|
|||||||
|
|
||||||
async def start_game(self):
|
async def start_game(self):
|
||||||
print(f"- Game #{self.game_id} STARTED ({self.game_state['player1_name']} vs {self.game_state['player2_name']}) --- ({self})")
|
print(f"- Game #{self.game_id} STARTED ({self.game_state['player1_name']} vs {self.game_state['player2_name']}) --- ({self})")
|
||||||
|
|
||||||
|
await sync_to_async(create_player)(self.game_state['player1_name'], self.game_state['player2_name'])
|
||||||
|
|
||||||
self.game_loop_task = asyncio.create_task(self.game_loop())
|
self.game_loop_task = asyncio.create_task(self.game_loop())
|
||||||
print(f" Begin MATCH at: {self.start_time}")
|
print(f" Begin MATCH at: {self.start_time}")
|
||||||
await sync_to_async(create_player)(self.game_state['player1_name'], self.game_state['player2_name'])
|
|
||||||
|
|
||||||
async def game_loop(self):
|
async def game_loop(self):
|
||||||
print(" In the game loop..")
|
print(" In the game loop..")
|
||||||
x = 59
|
x = 59
|
||||||
while not self.ended:
|
while not self.ended:
|
||||||
|
print(f" ended : {self.ended}")
|
||||||
if self.botgame:
|
if self.botgame:
|
||||||
x += 1
|
x += 1
|
||||||
if x == 60:
|
if x == 60:
|
||||||
@ -80,6 +82,33 @@ class Game:
|
|||||||
await self.update_game_state()
|
await self.update_game_state()
|
||||||
await self.send_game_state()
|
await self.send_game_state()
|
||||||
await asyncio.sleep(1/60) # Around 60 FPS
|
await asyncio.sleep(1/60) # Around 60 FPS
|
||||||
|
if self.ended:
|
||||||
|
print(f" IN WHILE EXIT ???????? ended : {self.ended}")
|
||||||
|
print("IN WHILE here !!!!!")
|
||||||
|
try:
|
||||||
|
await self.save_match()
|
||||||
|
print("IN WHILE end here !!!!")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Erreur lors de l'appel de save_match: {e}")
|
||||||
|
print(f" OUT WHILE EXIT ???????? ended : {self.ended}")
|
||||||
|
if self.ended :
|
||||||
|
print(" OUT WHILE here !!!!!")
|
||||||
|
try:
|
||||||
|
#await self.save_match()
|
||||||
|
print("OUT WHILE end here !!!!")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Erreur lors de l'appel de save_match: {e}")
|
||||||
|
|
||||||
|
async def save_match(self) :
|
||||||
|
avd, d = (True, self.tournament.tournoi_reg) if hasattr(self, 'tournament') else (False, None)
|
||||||
|
end_time = datetime.now()
|
||||||
|
duration = (end_time - self.start_time).total_seconds() / 60
|
||||||
|
print("CALL IN SYNC")
|
||||||
|
await sync_to_async(create_match, thread_sensitive=True)(self.game_state['player1_name'], self.game_state['player2_name'],
|
||||||
|
self.game_state['player1_score'], self.game_state['player2_score'],
|
||||||
|
self.bt1, self.bt2, duration, avd, d
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def update_bot_position(self):
|
async def update_bot_position(self):
|
||||||
#future_ball_position = self.predict_ball_trajectory()
|
#future_ball_position = self.predict_ball_trajectory()
|
||||||
@ -143,7 +172,7 @@ class Game:
|
|||||||
if self.game_state['player2_score'] > 2:
|
if self.game_state['player2_score'] > 2:
|
||||||
self.game_state['game_text'] = f"{self.game_state['player2_name']} WINS!"
|
self.game_state['game_text'] = f"{self.game_state['player2_name']} WINS!"
|
||||||
await self.send_game_state()
|
await self.send_game_state()
|
||||||
await self.end_game()
|
await self.end_game(self)
|
||||||
#printf("player2 wins")
|
#printf("player2 wins")
|
||||||
self.reset_ball()
|
self.reset_ball()
|
||||||
elif self.game_state['ball_position']['x'] >= 790:
|
elif self.game_state['ball_position']['x'] >= 790:
|
||||||
@ -151,7 +180,7 @@ class Game:
|
|||||||
if self.game_state['player1_score'] > 2:
|
if self.game_state['player1_score'] > 2:
|
||||||
self.game_state['game_text'] = f"{self.game_state['player1_name']} WINS!"
|
self.game_state['game_text'] = f"{self.game_state['player1_name']} WINS!"
|
||||||
await self.send_game_state()
|
await self.send_game_state()
|
||||||
await self.end_game()
|
await self.end_game(self)
|
||||||
#printf("player1 wins")
|
#printf("player1 wins")
|
||||||
self.reset_ball()
|
self.reset_ball()
|
||||||
|
|
||||||
@ -222,18 +251,16 @@ class Game:
|
|||||||
elif self.p2_mov == 1:
|
elif self.p2_mov == 1:
|
||||||
self.game_state['player2_position'] = min(self.game_state['player2_position'] + (5 * self.speed), 300)
|
self.game_state['player2_position'] = min(self.game_state['player2_position'] + (5 * self.speed), 300)
|
||||||
|
|
||||||
|
|
||||||
async def end_game(self, disconnected_player=None):
|
async def end_game(self, disconnected_player=None):
|
||||||
if not self.ended:
|
if not self.ended:
|
||||||
self.ended = True
|
self.ended = True
|
||||||
if self.game_loop_task:
|
|
||||||
self.game_loop_task.cancel()
|
|
||||||
print(f"- Game #{self.game_id} ENDED --- ({self})")
|
print(f"- Game #{self.game_id} ENDED --- ({self})")
|
||||||
|
|
||||||
end_time = datetime.now()
|
#await sync_to_async(save_match)()
|
||||||
duration = (end_time - self.start_time).total_seconds() / 60
|
|
||||||
|
|
||||||
# Notify that one player left the game
|
# Notify that one player left the game
|
||||||
if disconnected_player:
|
""" if disconnected_player:
|
||||||
printf("Disconnected player")
|
printf("Disconnected player")
|
||||||
remaining_player = self.player2 if disconnected_player == self.player1 else self.player1
|
remaining_player = self.player2 if disconnected_player == self.player1 else self.player1
|
||||||
disconnected_name = disconnected_player.user.username
|
disconnected_name = disconnected_player.user.username
|
||||||
@ -249,27 +276,30 @@ class Game:
|
|||||||
'type': 'game_ended',
|
'type': 'game_ended',
|
||||||
'game_id': self.game_id
|
'game_id': self.game_id
|
||||||
})
|
})
|
||||||
|
|
||||||
await self.player1.send(end_message)
|
await self.player1.send(end_message)
|
||||||
if not self.botgame:
|
if not self.botgame:
|
||||||
if not self.localgame:
|
if not self.localgame:
|
||||||
await self.player2.send(end_message)
|
await self.player2.send(end_message) """
|
||||||
|
|
||||||
|
|
||||||
print(f"Try to save game #{self.game_id} ({self})")
|
print(f"Try to save game #{self.game_id} ({self})")
|
||||||
|
|
||||||
|
|
||||||
avd, d = (True, self.tournament.tournoi_reg) if hasattr(self, 'tournament') else (False, None)
|
#avd, d = (True, self.tournament.tournoi_reg) if hasattr(self, 'tournament') else (False, None)
|
||||||
|
|
||||||
|
|
||||||
# Essaye d'appeler handle_game_data
|
# Essaye d'appeler handle_game_data
|
||||||
print("TRY CREATE MATCH")
|
print("TRY CREATE MATCH")
|
||||||
|
#await sync_to_async(create_match)(
|
||||||
await sync_to_async(create_match)(
|
# self.game_state['player1_name'], self.game_state['player2_name'],
|
||||||
self.game_state['player1_name'], self.game_state['player2_name'],
|
# self.game_state['player1_score'], self.game_state['player2_score'],
|
||||||
self.game_state['player1_score'], self.game_state['player2_score'],
|
# self.bt1, self.bt2, duration, avd, d
|
||||||
self.bt1, self.bt2, duration, avd, d
|
#)
|
||||||
)
|
|
||||||
|
|
||||||
print("MATCH OK")
|
print("MATCH OK")
|
||||||
|
|
||||||
|
#if self.game_loop_task:
|
||||||
|
# self.game_loop_task.cancel()
|
||||||
|
|
||||||
|
|
||||||
18
pong/game/migrations/0003_alter_tournoi_winner.py
Normal file
18
pong/game/migrations/0003_alter_tournoi_winner.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.1 on 2024-09-14 11:56
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('game', '0002_alter_match_player1_alter_match_player2_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='tournoi',
|
||||||
|
name='winner',
|
||||||
|
field=models.CharField(max_length=200),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
pong/game/migrations/0004_alter_tournoi_winner.py
Normal file
18
pong/game/migrations/0004_alter_tournoi_winner.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.1 on 2024-09-14 12:03
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('game', '0003_alter_tournoi_winner'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='tournoi',
|
||||||
|
name='winner',
|
||||||
|
field=models.CharField(blank=True, max_length=200, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
# Generated by Django 5.1.1 on 2024-09-14 12:41
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('game', '0004_alter_tournoi_winner'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='player',
|
||||||
|
name='num_won_tournaments',
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -11,7 +11,6 @@ class Player(models.Model):
|
|||||||
total_win = models.PositiveSmallIntegerField(default=0)
|
total_win = models.PositiveSmallIntegerField(default=0)
|
||||||
p_win = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True)
|
p_win = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True)
|
||||||
num_participated_tournaments = models.PositiveSmallIntegerField(default=0)
|
num_participated_tournaments = models.PositiveSmallIntegerField(default=0)
|
||||||
num_won_tournaments = models.PositiveSmallIntegerField(default=0)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
@ -20,7 +19,7 @@ class Tournoi(models.Model):
|
|||||||
name = models.CharField(max_length=200)
|
name = models.CharField(max_length=200)
|
||||||
nbr_player = models.PositiveSmallIntegerField()
|
nbr_player = models.PositiveSmallIntegerField()
|
||||||
date = models.DateField(auto_now_add=True)
|
date = models.DateField(auto_now_add=True)
|
||||||
winner = models.ForeignKey('Player', on_delete=models.SET_NULL, null=True)
|
winner = models.CharField(max_length=200, null=True, blank=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
@ -38,18 +37,5 @@ class Match(models.Model):
|
|||||||
is_tournoi = models.BooleanField()
|
is_tournoi = models.BooleanField()
|
||||||
tournoi = models.ForeignKey('Tournoi', related_name='matches', on_delete=models.SET_NULL, null=True)
|
tournoi = models.ForeignKey('Tournoi', related_name='matches', on_delete=models.SET_NULL, null=True)
|
||||||
|
|
||||||
def clean(self):
|
|
||||||
if self.score_player1 < 0 or self.score_player2 < 0:
|
|
||||||
raise ValidationError('Les scores doivent être positifs.')
|
|
||||||
if self.score_player1 > self.score_player2 and self.winner != self.player1:
|
|
||||||
raise ValidationError('Le gagnant ne correspond pas aux scores.')
|
|
||||||
if self.score_player2 > self.score_player1 and self.winner != self.player2:
|
|
||||||
raise ValidationError('Le gagnant ne correspond pas aux scores.')
|
|
||||||
super().clean()
|
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
|
||||||
self.clean()
|
|
||||||
super().save(*args, **kwargs)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.player1.name} vs {self.player2.name}"
|
return f"{self.player1} vs {self.player2}"
|
||||||
@ -8,6 +8,7 @@ from django.db.models import Q
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
players_name_list = []
|
players_name_list = []
|
||||||
|
tournament_participations = {}
|
||||||
|
|
||||||
def handle_game_data(p1, p2, s_p1, s_p2, bt_p1, bt_2, dur, is_tournoi, name_tournament):
|
def handle_game_data(p1, p2, s_p1, s_p2, bt_p1, bt_2, dur, is_tournoi, name_tournament):
|
||||||
try:
|
try:
|
||||||
@ -45,8 +46,7 @@ def create_player(name_p1, name_p2):
|
|||||||
total_match = 0,
|
total_match = 0,
|
||||||
total_win = 0,
|
total_win = 0,
|
||||||
p_win = 0,
|
p_win = 0,
|
||||||
num_participated_tournaments = 0,
|
num_participated_tournaments = 0)
|
||||||
num_won_tournaments = 0)
|
|
||||||
player1.save()
|
player1.save()
|
||||||
players_name_list.append(name_p1)
|
players_name_list.append(name_p1)
|
||||||
print(f"Player {name_p1} creation done")
|
print(f"Player {name_p1} creation done")
|
||||||
@ -60,8 +60,7 @@ def create_player(name_p1, name_p2):
|
|||||||
total_match = 0,
|
total_match = 0,
|
||||||
total_win = 0,
|
total_win = 0,
|
||||||
p_win = 0,
|
p_win = 0,
|
||||||
num_participated_tournaments = 0,
|
num_participated_tournaments = 0)
|
||||||
num_won_tournaments = 0)
|
|
||||||
player2.save()
|
player2.save()
|
||||||
players_name_list.append(name_p2)
|
players_name_list.append(name_p2)
|
||||||
print(f"Player {name_p2} creation done")
|
print(f"Player {name_p2} creation done")
|
||||||
@ -69,12 +68,6 @@ def create_player(name_p1, name_p2):
|
|||||||
#return player
|
#return player
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def create_tournoi(name, nbr_player, date, winner):
|
|
||||||
tournoi = Tournoi(name=name, nbr_player=nbr_player, date=date, winner=winner)
|
|
||||||
tournoi.save()
|
|
||||||
return tournoi
|
|
||||||
|
|
||||||
def create_match(player1, player2, score_player1, score_player2, nbr_ball_touch_p1, nbr_ball_touch_p2, duration, is_tournoi, tournoi):
|
def create_match(player1, player2, score_player1, score_player2, nbr_ball_touch_p1, nbr_ball_touch_p2, duration, is_tournoi, tournoi):
|
||||||
print("MATCH BEING REGISTERD")
|
print("MATCH BEING REGISTERD")
|
||||||
match = Match(
|
match = Match(
|
||||||
@ -100,57 +93,35 @@ def create_match(player1, player2, score_player1, score_player2, nbr_ball_touch_
|
|||||||
print("MATCH SAVE IN DB")
|
print("MATCH SAVE IN DB")
|
||||||
match.save()
|
match.save()
|
||||||
print("MATCH DONE")
|
print("MATCH DONE")
|
||||||
#update_player_statistics(player1)
|
update_player_statistics(player1, match.winner, is_tournoi, tournoi)
|
||||||
#update_player_statistics(player2)
|
print("STAT P1 DONE")
|
||||||
#print("STAT DONE")
|
update_player_statistics(player2, match.winner, is_tournoi, tournoi)
|
||||||
|
print("STAT P2 DONE")
|
||||||
|
|
||||||
|
def update_player_statistics(player_name, winner, is_tournoi, tournoi):
|
||||||
|
|
||||||
def update_player_statistics(player_name):
|
|
||||||
print("UPDATED DATA")
|
print("UPDATED DATA")
|
||||||
|
global tournament_participations
|
||||||
|
print("GET PLAYER")
|
||||||
player = get_object_or_404(Player, name=player_name)
|
player = get_object_or_404(Player, name=player_name)
|
||||||
|
print("PLAYER FIND")
|
||||||
|
|
||||||
matches = Match.objects.filter(Q(player1=player) | Q(player2=player))
|
|
||||||
|
|
||||||
total_match = matches.count()
|
|
||||||
|
|
||||||
|
|
||||||
# avoid dividing by 0
|
|
||||||
if total_match == 0:
|
|
||||||
player.total_match = total_match
|
|
||||||
player.total_win = 0
|
|
||||||
player.p_win = 0
|
|
||||||
player.num_participated_tournaments = 0
|
|
||||||
player.num_won_tournaments = 0
|
|
||||||
player.save()
|
|
||||||
return
|
|
||||||
|
|
||||||
nb_win =0
|
|
||||||
|
|
||||||
for match in matches :
|
|
||||||
if match.winner == player:
|
|
||||||
nb_win = nb_win + 1
|
|
||||||
|
|
||||||
|
|
||||||
#won_matches = Match.objects.filter(winner=player)
|
|
||||||
#part_tourn_as_p1 = Tournoi.objects.filter(matches__is_tournoi=True, matches__matches_as_player1=player)
|
|
||||||
#part_tourn_as_p2 = Tournoi.objects.filter(matches__is_tournoi=True, matches__matches_as_player2=player)
|
|
||||||
#won_tourn = Tournoi.objects.filter(winner=player)
|
|
||||||
|
|
||||||
|
|
||||||
#total_win = won_matches.count()
|
|
||||||
|
|
||||||
|
|
||||||
p_win = (nb_win/ total_match) * 100
|
|
||||||
|
|
||||||
#total_tourn_p = part_tourn_as_p1.count() + part_tourn_as_p2.count()
|
|
||||||
#total_win_tourn = won_tourn.count()
|
|
||||||
#p_win_tourn = (total_win_tourn / total_tourn_p) * 100 if total_tourn_p else 0
|
|
||||||
|
|
||||||
player.total_match = total_match
|
player.total_match += 1
|
||||||
player.total_win = total_win
|
if winner == player.name :
|
||||||
player.p_win = p_win
|
player.total_win += 1
|
||||||
# player.num_participated_tournaments = total_tourn_p
|
|
||||||
#player.num_won_tournaments = total_win_tourn
|
if player.total_match > 0:
|
||||||
|
player.p_win = player.total_win / player.total_match
|
||||||
|
|
||||||
|
if is_tournoi:
|
||||||
|
if tournoi.name not in tournament_participations:
|
||||||
|
tournament_participations[tournoi] = []
|
||||||
|
|
||||||
|
if player_name not in tournament_participations[tournoi]:
|
||||||
|
tournament_participations[tournoi].append(player.name)
|
||||||
|
player.num_participated_tournaments += 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
player.save()
|
player.save()
|
||||||
|
|
||||||
@ -160,19 +131,19 @@ def get_player_p_win(player_name):
|
|||||||
|
|
||||||
def create_tournament(name, nbr_player):
|
def create_tournament(name, nbr_player):
|
||||||
print("tournoi created!!!")
|
print("tournoi created!!!")
|
||||||
tournoi=Tournoi(name=name, nbr_player=nbr_player, winner=None)
|
tournoi=Tournoi(name=name, nbr_player=nbr_player, winner="No one yet ...")
|
||||||
tournoi.save()
|
tournoi.save()
|
||||||
print(f"tournoi name : {tournoi.name} *******!*!*!*!**!*!**!*!*!*!*!*!*!*!*!*")
|
print(f"tournoi name : {tournoi.name} *******!*!*!*!**!*!**!*!*!*!*!*!*!*!*!*")
|
||||||
return tournoi
|
return tournoi
|
||||||
|
|
||||||
def update_tournament(name_tournoi, winner_name):
|
def update_tournament(name_tournoi, winner_name):
|
||||||
tournoi = get_object_or_404(Tournoi, name=name_tournoi)
|
tournoi = get_object_or_404(Tournoi, name=name_tournoi)
|
||||||
winner_p = get_object_or_404(Player, name=winner_name)
|
|
||||||
print(f"in update tourna - tournoi name : {tournoi.name} *******!*!*!*!**!*!**!*!*!*!*!*!*!*!*!*")
|
print(f"in update tourna - tournoi name : {tournoi.name} *******!*!*!*!**!*!**!*!*!*!*!*!*!*!*!*")
|
||||||
print(f"in update tourna - winner is : {winner_p.name} *******!*!*!*!**!*!**!*!*!*!*!*!*!*!*!*")
|
|
||||||
|
|
||||||
tournoi.winner = winner_p
|
tournoi.winner = winner_name
|
||||||
print(f"in update tourna - TOURNOI winner is : {tournoi.winner.name} *******!*!*!*!**!*!**!*!*!*!*!*!*!*!*!*")
|
print(f"in update tourna - TOURNOI winner is : {tournoi.winner} *******!*!*!*!**!*!**!*!*!*!*!*!*!*!*!*")
|
||||||
tournoi.save()
|
tournoi.save()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from .models import Player, Tournoi, Match
|
from .models import Player, Tournoi, Match
|
||||||
from .utils import create_tournoi, create_match
|
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.auth import authenticate
|
from django.contrib.auth import authenticate
|
||||||
@ -84,7 +83,7 @@ def player_list_json(request):
|
|||||||
data = {
|
data = {
|
||||||
'players': list(players.values(
|
'players': list(players.values(
|
||||||
'id', 'name', 'total_match', 'total_win', 'p_win',
|
'id', 'name', 'total_match', 'total_win', 'p_win',
|
||||||
'num_participated_tournaments', 'num_won_tournaments'
|
'num_participated_tournaments'
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
return JsonResponse(data)
|
return JsonResponse(data)
|
||||||
@ -95,14 +94,11 @@ def get_tournoi_data(tournoi):
|
|||||||
"name": tournoi.name,
|
"name": tournoi.name,
|
||||||
"nbr_player": tournoi.nbr_player,
|
"nbr_player": tournoi.nbr_player,
|
||||||
"date": tournoi.date,
|
"date": tournoi.date,
|
||||||
"winner": {
|
"winner": tournoi.winner
|
||||||
"id": tournoi.winner.id,
|
|
||||||
"name": tournoi.winner.name
|
|
||||||
} if tournoi.winner else None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def tournoi_list_json(request):
|
def tournoi_list_json(request):
|
||||||
tournois = Tournoi.objects.select_related('winner').all() # Charge les données du gagnant
|
tournois = Tournoi.objects.all() # Charge les données du gagnant
|
||||||
tournois_data = [get_tournoi_data(tournoi) for tournoi in tournois]
|
tournois_data = [get_tournoi_data(tournoi) for tournoi in tournois]
|
||||||
return JsonResponse({"tournois": tournois_data})
|
return JsonResponse({"tournois": tournois_data})
|
||||||
|
|
||||||
|
|||||||
@ -147,7 +147,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
<td>${player.total_win}</td>
|
<td>${player.total_win}</td>
|
||||||
<td>${player.p_win}</td>
|
<td>${player.p_win}</td>
|
||||||
<td>${player.num_participated_tournaments}</td>
|
<td>${player.num_participated_tournaments}</td>
|
||||||
<td>${player.num_won_tournaments}</td>
|
|
||||||
`;
|
`;
|
||||||
playersListBody.appendChild(row);
|
playersListBody.appendChild(row);
|
||||||
});
|
});
|
||||||
@ -173,7 +172,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
<td>${tournoi.name}</td>
|
<td>${tournoi.name}</td>
|
||||||
<td>${tournoi.nbr_player}</td>
|
<td>${tournoi.nbr_player}</td>
|
||||||
<td>${tournoi.date}</td>
|
<td>${tournoi.date}</td>
|
||||||
<td>${tournoi.winner ? tournoi.winner.name : 'No one yet ...'}</td>
|
<td>${tournoi.winner}</td>
|
||||||
`;
|
`;
|
||||||
tournoisListBody.appendChild(row);
|
tournoisListBody.appendChild(row);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user