fix round listing from different wars
This commit is contained in:
parent
019e62565f
commit
4593400fd4
2 changed files with 35 additions and 26 deletions
|
|
@ -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():
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
if camp is not None:
|
||||||
camp.remove_round(round_id)
|
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)
|
||||||
|
if camp is not None:
|
||||||
return camp.create_choice(round_id, participant_id)
|
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)
|
||||||
|
if camp is not None:
|
||||||
camp.update_choice(
|
camp.update_choice(
|
||||||
round_id, participant_id, priority_sector_id, secondary_sector_id, comment
|
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)
|
||||||
|
if camp is not None:
|
||||||
camp.remove_choice(round_id, participant_id)
|
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)
|
||||||
|
if camp is not None:
|
||||||
return camp.create_battle(round_id, sector_id)
|
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,6 +311,7 @@ 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)
|
||||||
|
if camp is not None:
|
||||||
camp.update_battle(
|
camp.update_battle(
|
||||||
round_id,
|
round_id,
|
||||||
sector_id,
|
sector_id,
|
||||||
|
|
@ -317,4 +325,5 @@ class War:
|
||||||
|
|
||||||
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)
|
||||||
|
if camp is not None:
|
||||||
camp.remove_battle(round_id, sector_id)
|
camp.remove_battle(round_id, sector_id)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue