Display rank next to path

This commit is contained in:
Gabriel Augendre 2022-11-01 11:26:48 +01:00
parent 76d492a5b1
commit d80094cf41
3 changed files with 24 additions and 14 deletions

View file

@ -65,7 +65,7 @@ class Path(DocumentedModel, UniquelyNamedModel, TimeStampedModel, models.Model):
return None return None
def get_next_capability(self, character) -> Capability: def get_next_capability(self, character) -> Capability:
next_rank = character.capabilities.filter(path=self).count() + 1 next_rank = self.max_rank(character) + 1
return self.capabilities.get(rank=next_rank) return self.capabilities.get(rank=next_rank)
def has_next_capability(self, character) -> bool: def has_next_capability(self, character) -> bool:
@ -75,6 +75,9 @@ class Path(DocumentedModel, UniquelyNamedModel, TimeStampedModel, models.Model):
except Capability.DoesNotExist: except Capability.DoesNotExist:
return False return False
def max_rank(self, character) -> int:
return character.capabilities.filter(path=self).count()
class CapabilityManager(models.Manager): class CapabilityManager(models.Manager):
def get_by_natural_key(self, path, rank): def get_by_natural_key(self, path, rank):

View file

@ -1,22 +1,24 @@
{% load character_extras %} {% load character_extras %}
<div class="col-xl-3 col-md-6"> <div class="col col-md-6 col-xl-4">
<div class="card"> <div class="card">
<h5 class="card-header"> <h5 class="card-header">
{{ path.display_name }} {{ path.display_name }} ({{ path|max_rank:character }})
<div class="btn-group btn-group-sm">
<button hx-get="{% url "character:remove_last_in_path" character_pk=character.pk path_pk=path.pk %}" <button hx-get="{% url "character:remove_last_in_path" character_pk=character.pk path_pk=path.pk %}"
hx-target="#paths-and-capabilities" hx-target="#paths-and-capabilities"
hx-swap="outerHTML" hx-swap="outerHTML"
class="btn btn-sm btn-primary"> class="btn btn-primary">
<i class="fa-solid fa-minus"></i> <i class="fa-solid fa-minus"></i>
</button> </button>
{% if path|has_next_capability:character %} {% if path|has_next_capability:character %}
<button hx-get="{% url "character:add_next_in_path" character_pk=character.pk path_pk=path.pk %}" <button hx-get="{% url "character:add_next_in_path" character_pk=character.pk path_pk=path.pk %}"
hx-target="#paths-and-capabilities" hx-target="#paths-and-capabilities"
hx-swap="outerHTML" hx-swap="outerHTML"
class="btn btn-sm btn-primary"> class="btn btn-primary">
<i class="fa-solid fa-plus"></i> <i class="fa-solid fa-plus"></i>
</button> </button>
{% endif %} {% endif %}
</div>
</h5> </h5>
{% if path.notes %} {% if path.notes %}
<div class="card-body text-bg-light">{{ path.notes }}</div> <div class="card-body text-bg-light">{{ path.notes }}</div>

View file

@ -32,3 +32,8 @@ def weapon_modifier(character: Character, weapon: Weapon):
@register.filter @register.filter
def has_next_capability(path: Path, character: Character) -> bool: def has_next_capability(path: Path, character: Character) -> bool:
return path.has_next_capability(character) return path.has_next_capability(character)
@register.filter
def max_rank(path: Path, character: Character) -> int:
return path.max_rank(character)