fix round listing from different wars

This commit is contained in:
Maxime Réaux 2026-02-05 10:19:14 +01:00
parent 019e62565f
commit 4593400fd4
2 changed files with 35 additions and 26 deletions

View file

@ -349,8 +349,8 @@ class Model:
# Round methods # Round methods
def add_round(self, campaign_id: str) -> Round: def add_round(self, campaign_id: str) -> Round:
camp = self.get_campaign(campaign_id) war = self.get_war_by_campaign(campaign_id)
return camp.add_round() return war.add_round(campaign_id)
def get_round(self, round_id: str) -> Round: def get_round(self, round_id: str) -> Round:
for war in self.wars.values(): for war in self.wars.values():

View file

@ -139,12 +139,12 @@ class War:
return camp return camp
raise KeyError(f"Campaign {campaign_id} not found in War {self.id}") raise KeyError(f"Campaign {campaign_id} not found in War {self.id}")
def get_campaign_by_round(self, round_id: str) -> Campaign: def get_campaign_by_round(self, round_id: str) -> Campaign | None:
for camp in self.campaigns: for camp in self.campaigns:
for rnd in camp.rounds: for rnd in camp.rounds:
if rnd.id == round_id: if rnd.id == round_id:
return camp return camp
raise KeyError(f"Round {round_id} not found in any Campaign") return None
def get_campaign_by_sector(self, sector_id: str) -> Campaign: def get_campaign_by_sector(self, sector_id: str) -> Campaign:
for camp in self.campaigns: for camp in self.campaigns:
@ -255,19 +255,18 @@ class War:
camp = self.get_campaign(campaign_id) camp = self.get_campaign(campaign_id)
return camp.add_round() return camp.add_round()
def add_battle(self, campaign_id: str) -> Round:
camp = self.get_campaign(campaign_id)
return camp.add_round()
def remove_round(self, round_id: str) -> None: def remove_round(self, round_id: str) -> None:
camp = self.get_campaign_by_round(round_id) camp = self.get_campaign_by_round(round_id)
camp.remove_round(round_id) if camp is not None:
camp.remove_round(round_id)
# Choice methods # Choice methods
def create_choice(self, round_id: str, participant_id: str) -> Choice: def create_choice(self, round_id: str, participant_id: str) -> Choice:
camp = self.get_campaign_by_round(round_id) camp = self.get_campaign_by_round(round_id)
return camp.create_choice(round_id, participant_id) if camp is not None:
return camp.create_choice(round_id, participant_id)
raise KeyError("Campaign with round {round_id} doesn't exist")
def update_choice( def update_choice(
self, self,
@ -278,19 +277,27 @@ class War:
comment: str | None, comment: str | None,
) -> None: ) -> None:
camp = self.get_campaign_by_round(round_id) camp = self.get_campaign_by_round(round_id)
camp.update_choice( if camp is not None:
round_id, participant_id, priority_sector_id, secondary_sector_id, comment camp.update_choice(
) round_id,
participant_id,
priority_sector_id,
secondary_sector_id,
comment,
)
def remove_choice(self, round_id: str, participant_id: str) -> None: def remove_choice(self, round_id: str, participant_id: str) -> None:
camp = self.get_campaign_by_round(round_id) camp = self.get_campaign_by_round(round_id)
camp.remove_choice(round_id, participant_id) if camp is not None:
camp.remove_choice(round_id, participant_id)
# Battle methods # Battle methods
def create_battle(self, round_id: str, sector_id: str) -> Battle: def create_battle(self, round_id: str, sector_id: str) -> Battle:
camp = self.get_campaign_by_round(round_id) camp = self.get_campaign_by_round(round_id)
return camp.create_battle(round_id, sector_id) if camp is not None:
return camp.create_battle(round_id, sector_id)
raise KeyError("Campaign with round {round_id} doesn't exist")
def update_battle( def update_battle(
self, self,
@ -304,17 +311,19 @@ class War:
comment: str | None, comment: str | None,
) -> None: ) -> None:
camp = self.get_campaign_by_round(round_id) camp = self.get_campaign_by_round(round_id)
camp.update_battle( if camp is not None:
round_id, camp.update_battle(
sector_id, round_id,
player_1_id, sector_id,
player_2_id, player_1_id,
winner_id, player_2_id,
score, winner_id,
victory_condition, score,
comment, victory_condition,
) comment,
)
def remove_battle(self, round_id: str, sector_id: str) -> None: def remove_battle(self, round_id: str, sector_id: str) -> None:
camp = self.get_campaign_by_round(round_id) camp = self.get_campaign_by_round(round_id)
camp.remove_battle(round_id, sector_id) if camp is not None:
camp.remove_battle(round_id, sector_id)