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:
|
except RequiresConfirmation as e:
|
||||||
reply = QMessageBox.question(
|
reply = QMessageBox.question(
|
||||||
self.view,
|
self.view,
|
||||||
"Confirm deletion",
|
"Confirm update",
|
||||||
str(e),
|
str(e),
|
||||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
|
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
|
||||||
)
|
)
|
||||||
if reply == QMessageBox.StandardButton.Yes:
|
if reply == QMessageBox.StandardButton.Yes:
|
||||||
|
try:
|
||||||
e.action()
|
e.action()
|
||||||
|
except DomainError as inner:
|
||||||
|
QMessageBox.warning(
|
||||||
|
self.view,
|
||||||
|
"Update forbidden",
|
||||||
|
str(inner),
|
||||||
|
)
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
self.is_dirty = True
|
self.is_dirty = True
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ class RoundController:
|
||||||
self.app = app
|
self.app = app
|
||||||
|
|
||||||
def _fill_round_details(self, round_id: str) -> None:
|
def _fill_round_details(self, round_id: str) -> None:
|
||||||
|
# self.app.view.clear_round_page()
|
||||||
rnd = self.app.model.get_round(round_id)
|
rnd = self.app.model.get_round(round_id)
|
||||||
camp = self.app.model.get_campaign_by_round(round_id)
|
camp = self.app.model.get_campaign_by_round(round_id)
|
||||||
war = self.app.model.get_war_by_round(round_id)
|
war = self.app.model.get_war_by_round(round_id)
|
||||||
|
|
@ -57,9 +58,17 @@ class RoundController:
|
||||||
for part in participants:
|
for part in participants:
|
||||||
choice = rnd.get_choice(part.id)
|
choice = rnd.get_choice(part.id)
|
||||||
if not choice:
|
if not choice:
|
||||||
|
try:
|
||||||
choice = self.app.model.create_choice(
|
choice = self.app.model.create_choice(
|
||||||
round_id=rnd.id, participant_id=part.id
|
round_id=rnd.id, participant_id=part.id
|
||||||
)
|
)
|
||||||
|
except DomainError as e:
|
||||||
|
QMessageBox.warning(
|
||||||
|
self.app.view,
|
||||||
|
"Create forbidden",
|
||||||
|
str(e),
|
||||||
|
)
|
||||||
|
else:
|
||||||
priority_name = (
|
priority_name = (
|
||||||
camp.get_sector_name(choice.priority_sector_id)
|
camp.get_sector_name(choice.priority_sector_id)
|
||||||
if choice.priority_sector_id is not None
|
if choice.priority_sector_id is not None
|
||||||
|
|
@ -79,9 +88,13 @@ class RoundController:
|
||||||
part.id,
|
part.id,
|
||||||
)
|
)
|
||||||
if alloc.priority != ChoiceStatus.NONE:
|
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:
|
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:
|
if alloc.fallback:
|
||||||
fallback_icon = QIcon(Icons.get_pixmap(IconName.FALLBACK))
|
fallback_icon = QIcon(Icons.get_pixmap(IconName.FALLBACK))
|
||||||
choices_for_display.append(
|
choices_for_display.append(
|
||||||
|
|
@ -102,11 +115,18 @@ class RoundController:
|
||||||
battles_for_display: List[BattleDTO] = []
|
battles_for_display: List[BattleDTO] = []
|
||||||
for sect in sectors:
|
for sect in sectors:
|
||||||
battle = rnd.get_battle(sect.id)
|
battle = rnd.get_battle(sect.id)
|
||||||
|
|
||||||
if not battle:
|
if not battle:
|
||||||
|
try:
|
||||||
battle = self.app.model.create_battle(
|
battle = self.app.model.create_battle(
|
||||||
round_id=rnd.id, sector_id=sect.id
|
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)
|
state_icon = Icons.get(IconName.ONGOING)
|
||||||
if battle.is_finished():
|
if battle.is_finished():
|
||||||
state_icon = Icons.get(IconName.DONE)
|
state_icon = Icons.get(IconName.DONE)
|
||||||
|
|
|
||||||
|
|
@ -144,8 +144,8 @@ class Campaign:
|
||||||
|
|
||||||
def cleanup() -> None:
|
def cleanup() -> None:
|
||||||
for rnd in rounds_blocking:
|
for rnd in rounds_blocking:
|
||||||
rnd.clear_participant_references(participant_id)
|
|
||||||
rnd.remove_choice(participant_id)
|
rnd.remove_choice(participant_id)
|
||||||
|
rnd.clear_participant_references(participant_id)
|
||||||
del self.participants[participant_id]
|
del self.participants[participant_id]
|
||||||
|
|
||||||
rounds_str = ", ".join(
|
rounds_str = ", ".join(
|
||||||
|
|
@ -263,8 +263,8 @@ class Campaign:
|
||||||
|
|
||||||
def cleanup_and_update() -> None:
|
def cleanup_and_update() -> None:
|
||||||
for rnd in affected_rounds:
|
for rnd in affected_rounds:
|
||||||
rnd.clear_sector_references(sector_id)
|
|
||||||
rnd.remove_battle(sector_id)
|
rnd.remove_battle(sector_id)
|
||||||
|
rnd.clear_sector_references(sector_id)
|
||||||
apply_update()
|
apply_update()
|
||||||
|
|
||||||
rounds_str = ", ".join(
|
rounds_str = ", ".join(
|
||||||
|
|
@ -299,8 +299,8 @@ class Campaign:
|
||||||
|
|
||||||
def cleanup() -> None:
|
def cleanup() -> None:
|
||||||
for rnd in rounds_blocking:
|
for rnd in rounds_blocking:
|
||||||
rnd.clear_sector_references(sector_id)
|
|
||||||
rnd.remove_battle(sector_id)
|
rnd.remove_battle(sector_id)
|
||||||
|
rnd.clear_sector_references(sector_id)
|
||||||
del self.sectors[sector_id]
|
del self.sectors[sector_id]
|
||||||
|
|
||||||
rounds_str = ", ".join(
|
rounds_str = ", ".join(
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,6 @@ class Round:
|
||||||
|
|
||||||
def create_choice(self, participant_id: str) -> Choice:
|
def create_choice(self, participant_id: str) -> Choice:
|
||||||
if self.is_over:
|
if self.is_over:
|
||||||
# TODO catch me if you can
|
|
||||||
raise ForbiddenOperation("Can't create choice in a closed round.")
|
raise ForbiddenOperation("Can't create choice in a closed round.")
|
||||||
if participant_id not in self.choices:
|
if participant_id not in self.choices:
|
||||||
choice = Choice(
|
choice = Choice(
|
||||||
|
|
@ -97,13 +96,16 @@ class Round:
|
||||||
comment: str | None,
|
comment: str | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
if self.is_over:
|
if self.is_over:
|
||||||
# TODO catch me if you can
|
|
||||||
raise ForbiddenOperation("Can't update choice in a closed round.")
|
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)
|
choice = self.get_choice(participant_id)
|
||||||
if choice:
|
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_priority(priority_sector_id)
|
||||||
choice.set_secondary(secondary_sector_id)
|
choice.set_secondary(secondary_sector_id)
|
||||||
choice.set_comment(comment)
|
choice.set_comment(comment)
|
||||||
|
|
@ -124,10 +126,8 @@ class Round:
|
||||||
if participant_id not in self.choices:
|
if participant_id not in self.choices:
|
||||||
return
|
return
|
||||||
if self.is_over:
|
if self.is_over:
|
||||||
# TODO catch me if you can (inner)
|
|
||||||
raise ForbiddenOperation("Can't remove choice in a closed round.")
|
raise ForbiddenOperation("Can't remove choice in a closed round.")
|
||||||
if self.has_battle_with_participant(participant_id):
|
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.")
|
raise ForbiddenOperation("Can't remove choice already assigned to battle.")
|
||||||
self.war.revert_choice_ties(
|
self.war.revert_choice_ties(
|
||||||
self.id,
|
self.id,
|
||||||
|
|
@ -176,7 +176,6 @@ class Round:
|
||||||
|
|
||||||
def create_battle(self, sector_id: str) -> Battle:
|
def create_battle(self, sector_id: str) -> Battle:
|
||||||
if self.is_over:
|
if self.is_over:
|
||||||
# TODO catch me if you can
|
|
||||||
raise ForbiddenOperation("Can't create battle in a closed round.")
|
raise ForbiddenOperation("Can't create battle in a closed round.")
|
||||||
if sector_id not in self.battles:
|
if sector_id not in self.battles:
|
||||||
battle = Battle(sector_id=sector_id, player_1_id=None, player_2_id=None)
|
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
|
from warchron.model.pairing import Pairing
|
||||||
|
|
||||||
if self.is_over:
|
if self.is_over:
|
||||||
# TODO catch me if you can
|
|
||||||
raise ForbiddenOperation("Can't update battle in a closed round.")
|
raise ForbiddenOperation("Can't update battle in a closed round.")
|
||||||
bat = self.get_battle(sector_id)
|
bat = self.get_battle(sector_id)
|
||||||
if not bat:
|
if not bat:
|
||||||
|
|
@ -274,11 +272,9 @@ class Round:
|
||||||
if sector_id not in self.battles:
|
if sector_id not in self.battles:
|
||||||
return
|
return
|
||||||
if self.is_over:
|
if self.is_over:
|
||||||
# TODO catch me if you can
|
|
||||||
raise ForbiddenOperation("Can't remove battle in a closed round.")
|
raise ForbiddenOperation("Can't remove battle in a closed round.")
|
||||||
bat = self.battles[sector_id]
|
bat = self.battles[sector_id]
|
||||||
if bat and bat.is_finished():
|
if bat and bat.is_finished():
|
||||||
# TODO catch me if you can
|
|
||||||
raise ForbiddenOperation("Can't remove finished battle.")
|
raise ForbiddenOperation("Can't remove finished battle.")
|
||||||
self.war.revert_battle_ties(self.id, sector_id=sector_id)
|
self.war.revert_battle_ties(self.id, sector_id=sector_id)
|
||||||
del self.battles[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:
|
def show_round_details(self, *, index: int | None) -> None:
|
||||||
self.roundNb.setText(f"Round {index}")
|
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:
|
def display_round_choices(self, participants: List[ChoiceDTO]) -> None:
|
||||||
table = self.choicesTable
|
table = self.choicesTable
|
||||||
table.setSortingEnabled(False)
|
table.setSortingEnabled(False)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue