fix uncaucht choice/battle exceptions
This commit is contained in:
parent
f5ad45f671
commit
0081e52e9a
5 changed files with 156 additions and 126 deletions
|
|
@ -357,12 +357,20 @@ class AppController:
|
|||
except RequiresConfirmation as e:
|
||||
reply = QMessageBox.question(
|
||||
self.view,
|
||||
"Confirm deletion",
|
||||
"Confirm update",
|
||||
str(e),
|
||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
|
||||
)
|
||||
if reply == QMessageBox.StandardButton.Yes:
|
||||
try:
|
||||
e.action()
|
||||
except DomainError as inner:
|
||||
QMessageBox.warning(
|
||||
self.view,
|
||||
"Update forbidden",
|
||||
str(inner),
|
||||
)
|
||||
return
|
||||
else:
|
||||
return
|
||||
self.is_dirty = True
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ class RoundController:
|
|||
self.app = app
|
||||
|
||||
def _fill_round_details(self, round_id: str) -> None:
|
||||
# self.app.view.clear_round_page()
|
||||
rnd = self.app.model.get_round(round_id)
|
||||
camp = self.app.model.get_campaign_by_round(round_id)
|
||||
war = self.app.model.get_war_by_round(round_id)
|
||||
|
|
@ -57,9 +58,17 @@ class RoundController:
|
|||
for part in participants:
|
||||
choice = rnd.get_choice(part.id)
|
||||
if not choice:
|
||||
try:
|
||||
choice = self.app.model.create_choice(
|
||||
round_id=rnd.id, participant_id=part.id
|
||||
)
|
||||
except DomainError as e:
|
||||
QMessageBox.warning(
|
||||
self.app.view,
|
||||
"Create forbidden",
|
||||
str(e),
|
||||
)
|
||||
else:
|
||||
priority_name = (
|
||||
camp.get_sector_name(choice.priority_sector_id)
|
||||
if choice.priority_sector_id is not None
|
||||
|
|
@ -79,9 +88,13 @@ class RoundController:
|
|||
part.id,
|
||||
)
|
||||
if alloc.priority != ChoiceStatus.NONE:
|
||||
priority_icon = QIcon(Icons.get_pixmap(IconName[alloc.priority.name]))
|
||||
priority_icon = QIcon(
|
||||
Icons.get_pixmap(IconName[alloc.priority.name])
|
||||
)
|
||||
if alloc.secondary != ChoiceStatus.NONE:
|
||||
secondary_icon = QIcon(Icons.get_pixmap(IconName[alloc.secondary.name]))
|
||||
secondary_icon = QIcon(
|
||||
Icons.get_pixmap(IconName[alloc.secondary.name])
|
||||
)
|
||||
if alloc.fallback:
|
||||
fallback_icon = QIcon(Icons.get_pixmap(IconName.FALLBACK))
|
||||
choices_for_display.append(
|
||||
|
|
@ -102,11 +115,18 @@ class RoundController:
|
|||
battles_for_display: List[BattleDTO] = []
|
||||
for sect in sectors:
|
||||
battle = rnd.get_battle(sect.id)
|
||||
|
||||
if not battle:
|
||||
try:
|
||||
battle = self.app.model.create_battle(
|
||||
round_id=rnd.id, sector_id=sect.id
|
||||
)
|
||||
except DomainError as e:
|
||||
QMessageBox.warning(
|
||||
self.app.view,
|
||||
"Create forbidden",
|
||||
str(e),
|
||||
)
|
||||
else:
|
||||
state_icon = Icons.get(IconName.ONGOING)
|
||||
if battle.is_finished():
|
||||
state_icon = Icons.get(IconName.DONE)
|
||||
|
|
|
|||
|
|
@ -144,8 +144,8 @@ class Campaign:
|
|||
|
||||
def cleanup() -> None:
|
||||
for rnd in rounds_blocking:
|
||||
rnd.clear_participant_references(participant_id)
|
||||
rnd.remove_choice(participant_id)
|
||||
rnd.clear_participant_references(participant_id)
|
||||
del self.participants[participant_id]
|
||||
|
||||
rounds_str = ", ".join(
|
||||
|
|
@ -263,8 +263,8 @@ class Campaign:
|
|||
|
||||
def cleanup_and_update() -> None:
|
||||
for rnd in affected_rounds:
|
||||
rnd.clear_sector_references(sector_id)
|
||||
rnd.remove_battle(sector_id)
|
||||
rnd.clear_sector_references(sector_id)
|
||||
apply_update()
|
||||
|
||||
rounds_str = ", ".join(
|
||||
|
|
@ -299,8 +299,8 @@ class Campaign:
|
|||
|
||||
def cleanup() -> None:
|
||||
for rnd in rounds_blocking:
|
||||
rnd.clear_sector_references(sector_id)
|
||||
rnd.remove_battle(sector_id)
|
||||
rnd.clear_sector_references(sector_id)
|
||||
del self.sectors[sector_id]
|
||||
|
||||
rounds_str = ", ".join(
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -599,6 +599,12 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||
def show_round_details(self, *, index: int | None) -> None:
|
||||
self.roundNb.setText(f"Round {index}")
|
||||
|
||||
def clear_round_page(self) -> None:
|
||||
choices_table = self.choicesTable
|
||||
choices_table.clearContents()
|
||||
battles_table = self.battlesTable
|
||||
battles_table.clearContents()
|
||||
|
||||
def display_round_choices(self, participants: List[ChoiceDTO]) -> None:
|
||||
table = self.choicesTable
|
||||
table.setSortingEnabled(False)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue