diff --git a/src/character/models/character.py b/src/character/models/character.py index 90d65a9..239fc04 100644 --- a/src/character/models/character.py +++ b/src/character/models/character.py @@ -1,5 +1,6 @@ import collections from collections.abc import Iterable +from dataclasses import dataclass import markdown from django.db import models @@ -105,6 +106,12 @@ DEFAULT_NOTES = """ """.lstrip() +@dataclass +class CharacterCapability: + capability: Capability + known: bool = False + + class Character(models.Model): class Gender(models.TextChoices): MALE = "M", "Mâle" @@ -333,15 +340,22 @@ class Character(models.Model): } return modifier_map.get(Weapon.Category(weapon.category), 0) + self.level - def get_capabilities_by_path(self) -> dict[Path, list[Capability]]: + def get_capabilities_by_path(self) -> dict[Path, list[CharacterCapability]]: capabilities_by_path = collections.defaultdict(list) - for capability in self.capabilities.all(): - capabilities_by_path[capability.path].append(capability) + character_capabilities = self.capabilities.all() + character_paths = {capability.path for capability in character_capabilities} + for path in character_paths: + for capability in path.capabilities.all(): + capabilities_by_path[capability.path].append( + CharacterCapability( + capability, known=capability in character_capabilities + ) + ) return dict( sorted( ( - (path, sorted(capabilities, key=lambda x: x.rank)) + (path, sorted(capabilities, key=lambda x: x.capability.rank)) for path, capabilities in capabilities_by_path.items() ), key=lambda x: x[0].name, diff --git a/src/character/templates/character/snippets/character_details/capability.html b/src/character/templates/character/snippets/character_details/capability.html index cbbfd0f..792c1ce 100644 --- a/src/character/templates/character/snippets/character_details/capability.html +++ b/src/character/templates/character/snippets/character_details/capability.html @@ -1,16 +1,18 @@ -