From 4593400fd498f1e699489ab0bd3593cb45a3f10e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20R=C3=A9aux?= Date: Thu, 5 Feb 2026 10:19:14 +0100 Subject: [PATCH] fix round listing from different wars --- src/warchron/model/model.py | 4 +-- src/warchron/model/war.py | 57 +++++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/warchron/model/model.py b/src/warchron/model/model.py index dd0ad09..195d76e 100644 --- a/src/warchron/model/model.py +++ b/src/warchron/model/model.py @@ -349,8 +349,8 @@ class Model: # Round methods def add_round(self, campaign_id: str) -> Round: - camp = self.get_campaign(campaign_id) - return camp.add_round() + war = self.get_war_by_campaign(campaign_id) + return war.add_round(campaign_id) def get_round(self, round_id: str) -> Round: for war in self.wars.values(): diff --git a/src/warchron/model/war.py b/src/warchron/model/war.py index 2a895a2..390be66 100644 --- a/src/warchron/model/war.py +++ b/src/warchron/model/war.py @@ -139,12 +139,12 @@ class War: return camp 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 rnd in camp.rounds: if rnd.id == round_id: 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: for camp in self.campaigns: @@ -255,19 +255,18 @@ class War: camp = self.get_campaign(campaign_id) 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: 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 def create_choice(self, round_id: str, participant_id: str) -> Choice: 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( self, @@ -278,19 +277,27 @@ class War: comment: str | None, ) -> None: camp = self.get_campaign_by_round(round_id) - camp.update_choice( - round_id, participant_id, priority_sector_id, secondary_sector_id, comment - ) + if camp is not None: + 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: 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 def create_battle(self, round_id: str, sector_id: str) -> Battle: 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( self, @@ -304,17 +311,19 @@ class War: comment: str | None, ) -> None: camp = self.get_campaign_by_round(round_id) - camp.update_battle( - round_id, - sector_id, - player_1_id, - player_2_id, - winner_id, - score, - victory_condition, - comment, - ) + if camp is not None: + camp.update_battle( + round_id, + sector_id, + player_1_id, + player_2_id, + winner_id, + score, + victory_condition, + comment, + ) def remove_battle(self, round_id: str, sector_id: str) -> None: 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)