fix uncaucht choice/battle exceptions
This commit is contained in:
parent
f5ad45f671
commit
0081e52e9a
5 changed files with 156 additions and 126 deletions
|
|
@ -78,7 +78,6 @@ class Round:
|
|||
|
||||
def create_choice(self, participant_id: str) -> Choice:
|
||||
if self.is_over:
|
||||
# TODO catch me if you can
|
||||
raise ForbiddenOperation("Can't create choice in a closed round.")
|
||||
if participant_id not in self.choices:
|
||||
choice = Choice(
|
||||
|
|
@ -97,13 +96,16 @@ class Round:
|
|||
comment: str | None,
|
||||
) -> None:
|
||||
if self.is_over:
|
||||
# TODO catch me if you can
|
||||
raise ForbiddenOperation("Can't update choice in a closed round.")
|
||||
if self.has_battle_with_participant(participant_id):
|
||||
# TODO catch me if you can (inner)
|
||||
raise ForbiddenOperation("Can't update choice already assigned to battle.")
|
||||
choice = self.get_choice(participant_id)
|
||||
if choice:
|
||||
if self.has_battle_with_participant(participant_id) and (
|
||||
priority_sector_id != choice.priority_sector_id
|
||||
or secondary_sector_id != choice.secondary_sector_id
|
||||
):
|
||||
raise ForbiddenOperation(
|
||||
"Can't update choice already assigned to battle."
|
||||
)
|
||||
choice.set_priority(priority_sector_id)
|
||||
choice.set_secondary(secondary_sector_id)
|
||||
choice.set_comment(comment)
|
||||
|
|
@ -124,10 +126,8 @@ class Round:
|
|||
if participant_id not in self.choices:
|
||||
return
|
||||
if self.is_over:
|
||||
# TODO catch me if you can (inner)
|
||||
raise ForbiddenOperation("Can't remove choice in a closed round.")
|
||||
if self.has_battle_with_participant(participant_id):
|
||||
# TODO catch me if you can (inner)
|
||||
raise ForbiddenOperation("Can't remove choice already assigned to battle.")
|
||||
self.war.revert_choice_ties(
|
||||
self.id,
|
||||
|
|
@ -176,7 +176,6 @@ class Round:
|
|||
|
||||
def create_battle(self, sector_id: str) -> Battle:
|
||||
if self.is_over:
|
||||
# TODO catch me if you can
|
||||
raise ForbiddenOperation("Can't create battle in a closed round.")
|
||||
if sector_id not in self.battles:
|
||||
battle = Battle(sector_id=sector_id, player_1_id=None, player_2_id=None)
|
||||
|
|
@ -196,7 +195,6 @@ class Round:
|
|||
from warchron.model.pairing import Pairing
|
||||
|
||||
if self.is_over:
|
||||
# TODO catch me if you can
|
||||
raise ForbiddenOperation("Can't update battle in a closed round.")
|
||||
bat = self.get_battle(sector_id)
|
||||
if not bat:
|
||||
|
|
@ -274,11 +272,9 @@ class Round:
|
|||
if sector_id not in self.battles:
|
||||
return
|
||||
if self.is_over:
|
||||
# TODO catch me if you can
|
||||
raise ForbiddenOperation("Can't remove battle in a closed round.")
|
||||
bat = self.battles[sector_id]
|
||||
if bat and bat.is_finished():
|
||||
# TODO catch me if you can
|
||||
raise ForbiddenOperation("Can't remove finished battle.")
|
||||
self.war.revert_battle_ties(self.id, sector_id=sector_id)
|
||||
del self.battles[sector_id]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue