Skip to content

Commit

Permalink
feat: Add validation for card settings template in ProfileView
Browse files Browse the repository at this point in the history
  • Loading branch information
seriaati committed Feb 3, 2025
1 parent 79ed8a5 commit 7899643
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions hoyo_buddy/ui/hoyo/profile/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from hoyo_buddy.ui import Button, Select, View
from hoyo_buddy.ui.hoyo.profile.items.image_settings_btn import ImageSettingsButton
from hoyo_buddy.ui.hoyo.profile.items.team_card_settings_btn import TeamCardSettingsButton
from hoyo_buddy.ui.hoyo.profile.templates import TEMPLATES
from hoyo_buddy.utils import blur_uid, format_float, human_format_number

from .card_settings import get_card_settings
Expand Down Expand Up @@ -137,6 +138,11 @@ async def fetch_cache_extras(self) -> dict[str, Any]:
self.cache_extras = cache.extras
return cache.extras

async def _fix_invalid_template(self, card_settings: CardSettings) -> None:
if self.game not in TEMPLATES or card_settings.template not in TEMPLATES[self.game]:
card_settings.template = "hb1"
await card_settings.save(update_fields=("template",))

async def _get_character_rank(
self, character: Character, *, with_detail: bool = False
) -> str | None:
Expand Down Expand Up @@ -533,6 +539,8 @@ async def draw_card(
card_settings.template = "hb1"
await card_settings.save(update_fields=("template",))

await self._fix_invalid_template(card_settings)

template = card_settings.template
draw_input = DrawInput(
dark_mode=card_settings.dark_mode,
Expand Down

0 comments on commit 7899643

Please sign in to comment.