From 833584a2b72949ef97cd22f544be54e4463a479f Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sun, 6 Nov 2022 15:06:29 +0100 Subject: [PATCH] Add view capability --- src/character/models/character.py | 3 + .../character/character_details.html | 424 +++++++++--------- .../damage_reduction_display.html | 17 +- .../character_details/equipment_display.html | 17 +- .../character_details/notes_display.html | 17 +- .../snippets/character_details/path.html | 28 +- .../paths_and_capabilities.html | 35 +- .../characters_list/character_card.html | 15 +- .../templatetags/character_extras.py | 6 + src/character/views.py | 2 +- 10 files changed, 307 insertions(+), 257 deletions(-) diff --git a/src/character/models/character.py b/src/character/models/character.py index b45133e..bbf4110 100644 --- a/src/character/models/character.py +++ b/src/character/models/character.py @@ -337,3 +337,6 @@ class Character(models.Model): return HarmfulState.objects.exclude( pk__in=self.states.all().values_list("pk", flat=True) ) + + def managed_by(self, user): + return self in Character.objects.managed_by(user) diff --git a/src/character/templates/character/character_details.html b/src/character/templates/character/character_details.html index 681e209..32b2428 100644 --- a/src/character/templates/character/character_details.html +++ b/src/character/templates/character/character_details.html @@ -7,9 +7,11 @@ {% block content %}

{{ character.name }}

-

- Edit -

+ {% if character|managed_by:user %} +

+ Edit +

+ {% endif %}

Joueur : {{ character.player.get_full_name|default:character.player.username }}

@@ -28,30 +30,32 @@ Initiative divers -
- - - - -
+ {% if character|managed_by:user %} +
+ + + + +
+ {% endif %} {{ character.initiative_misc }} @@ -62,8 +66,10 @@ + {% if character|managed_by:user %} + hx-get="{% url "character:get_initiative" pk=character.pk %}" + hx-trigger="update_initiative from:#fight-table" + {% endif %}> {{ character.modifier_initiative|modifier }} @@ -103,30 +109,32 @@ Armure -
- - - - -
+ {% if character|managed_by:user %} +
+ + + + +
+ {% endif %} {{ character.armor }} @@ -135,30 +143,32 @@ Bouclier -
- - - - -
+ {% if character|managed_by:user %} +
+ + + + +
+ {% endif %} {{ character.shield }} @@ -167,30 +177,32 @@ Divers défense -
- - - - -
+ {% if character|managed_by:user %} +
+ + + + +
+ {% endif %} {{ character.defense_misc }} @@ -201,8 +213,10 @@ + {% if character|managed_by:user %} + hx-get="{% url "character:get_defense" pk=character.pk %}" + hx-trigger="update_defense from:#fight-table" + {% endif %}> {{ character.defense }} @@ -218,64 +232,68 @@ Points de vie -
- - - - -
+ {% if character|managed_by:user %} +
+ + + + +
+ {% endif %} {{ character.health_remaining }} / {{ character.health_max }} Points de mana -
- - - - -
+ {% if character|managed_by:user %} +
+ + + + +
+ {% endif %} Points de récup. -
- - - - -
+ {% if character|managed_by:user %} +
+ + + + +
+ {% endif %} {{ character.recovery_points_remaining }} / {{ character.recovery_points_max }} @@ -320,30 +340,32 @@ Points de chance -
- - - - -
+ {% if character|managed_by:user %} +
+ + + + +
+ {% endif %}
Réduction de dégâts - - Edit - + {% if character|managed_by:user %} + + Edit + + {% endif %}

diff --git a/src/character/templates/character/snippets/character_details/equipment_display.html b/src/character/templates/character/snippets/character_details/equipment_display.html index fa4b71a..242d76e 100644 --- a/src/character/templates/character/snippets/character_details/equipment_display.html +++ b/src/character/templates/character/snippets/character_details/equipment_display.html @@ -1,13 +1,16 @@ +{% load character_extras %}

Équipement - - Edit - + {% if character|managed_by:user %} + + Edit + + {% endif %}

diff --git a/src/character/templates/character/snippets/character_details/notes_display.html b/src/character/templates/character/snippets/character_details/notes_display.html index 725018a..2135d7b 100644 --- a/src/character/templates/character/snippets/character_details/notes_display.html +++ b/src/character/templates/character/snippets/character_details/notes_display.html @@ -1,13 +1,16 @@ +{% load character_extras %}

Notes - - Edit - + {% if character|managed_by:user %} + + Edit + + {% endif %}

{{ character.get_formatted_notes|safe }}
diff --git a/src/character/templates/character/snippets/character_details/path.html b/src/character/templates/character/snippets/character_details/path.html index ec85627..0b80b17 100644 --- a/src/character/templates/character/snippets/character_details/path.html +++ b/src/character/templates/character/snippets/character_details/path.html @@ -2,22 +2,24 @@
{{ path.display_name }} ({{ path|max_rank:character }}) -
- - {% if path|has_next_capability:character %} - - {% endif %} -
+ {% if path|has_next_capability:character %} + + {% endif %} +
+ {% endif %} {% if path.notes %}
{{ path.notes }}
diff --git a/src/character/templates/character/snippets/character_details/paths_and_capabilities.html b/src/character/templates/character/snippets/character_details/paths_and_capabilities.html index 647f305..223f999 100644 --- a/src/character/templates/character/snippets/character_details/paths_and_capabilities.html +++ b/src/character/templates/character/snippets/character_details/paths_and_capabilities.html @@ -1,23 +1,26 @@ +{% load character_extras %} {% load django_bootstrap5 %}
-
- {% csrf_token %} -
-
- {% bootstrap_form_errors add_path_form %} -
- {{ add_path_form.character_path }} - {{ add_path_form.other_path }} - + {% if character|managed_by:user %} + + {% csrf_token %} +
+
+ {% bootstrap_form_errors add_path_form %} +
+ {{ add_path_form.character_path }} + {{ add_path_form.other_path }} + +
-
- + + {% endif %}
{% for path, capabilities in character.get_capabilities_by_path.items %} {% include "character/snippets/character_details/path.html" %} diff --git a/src/character/templates/character/snippets/characters_list/character_card.html b/src/character/templates/character/snippets/characters_list/character_card.html index 00dc287..e951d36 100644 --- a/src/character/templates/character/snippets/characters_list/character_card.html +++ b/src/character/templates/character/snippets/characters_list/character_card.html @@ -1,3 +1,4 @@ +{% load character_extras %}
@@ -21,18 +22,22 @@ {% endfor %} {% endwith %}

- {% if character.player == user %} -
+
+ {% if character|managed_by:user %} - Jouer + {% if character.player == user %}Jouer{% else %}Gérer{% endif %} {% if party %} Quitter le groupe {% endif %} -
- {% endif %} + {% else %} + + Observer + + {% endif %} +
diff --git a/src/character/templatetags/character_extras.py b/src/character/templatetags/character_extras.py index d3915d6..1c63cd5 100644 --- a/src/character/templatetags/character_extras.py +++ b/src/character/templatetags/character_extras.py @@ -1,6 +1,7 @@ from django import template from character.models import Character, Path, Weapon +from common.models import User register = template.Library() @@ -37,3 +38,8 @@ def has_next_capability(path: Path, character: Character) -> bool: @register.filter def max_rank(path: Path, character: Character) -> int: return path.max_rank(character) + + +@register.filter +def managed_by(character: Character, user: User) -> bool: + return character.managed_by(user) diff --git a/src/character/views.py b/src/character/views.py index 6ba56b8..35b05b8 100644 --- a/src/character/views.py +++ b/src/character/views.py @@ -27,7 +27,7 @@ def character_create(request): @login_required def character_view(request, pk: int): character = get_object_or_404( - Character.objects.managed_by(request.user) + Character.objects.all() .select_related("player", "racial_capability", "profile", "race") .prefetch_related("capabilities__path", "weapons"), pk=pk,