mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-11-05 06:13:55 +01:00
Add view capability
This commit is contained in:
parent
9033c8453c
commit
833584a2b7
10 changed files with 307 additions and 257 deletions
|
@ -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)
|
||||
|
|
|
@ -7,9 +7,11 @@
|
|||
|
||||
{% block content %}
|
||||
<h1>{{ character.name }}</h1>
|
||||
{% if character|managed_by:user %}
|
||||
<p>
|
||||
<a href="{% url "admin:character_character_change" object_id=character.pk %}">Edit</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
<p>
|
||||
Joueur : {{ character.player.get_full_name|default:character.player.username }}
|
||||
</p>
|
||||
|
@ -28,6 +30,7 @@
|
|||
<tr>
|
||||
<th scope="row">
|
||||
Initiative divers
|
||||
{% if character|managed_by:user %}
|
||||
<div class="btn-group btn-group-sm float-end" role="group">
|
||||
<button
|
||||
hx-get="{% url "character:initiative_misc_change" pk=character.pk %}?value=ko"
|
||||
|
@ -52,6 +55,7 @@
|
|||
disabled
|
||||
class="btn btn-outline-secondary"><i class="fa-solid fa-battery-full"></i></button>
|
||||
</div>
|
||||
{% endif %}
|
||||
</th>
|
||||
<td id="initiative-misc">
|
||||
{{ character.initiative_misc }}
|
||||
|
@ -62,8 +66,10 @@
|
|||
<td data-bs-toggle="tooltip"
|
||||
data-bs-placement="left"
|
||||
data-bs-title="{{ character.modifier_dexterity }} (mod. DEX) + {{ character.initiative_misc }} (divers)"
|
||||
{% if character|managed_by:user %}
|
||||
hx-get="{% url "character:get_initiative" pk=character.pk %}"
|
||||
hx-trigger="update_initiative from:#fight-table">
|
||||
hx-trigger="update_initiative from:#fight-table"
|
||||
{% endif %}>
|
||||
{{ character.modifier_initiative|modifier }}
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -103,6 +109,7 @@
|
|||
<tr>
|
||||
<th scope="row">
|
||||
Armure
|
||||
{% if character|managed_by:user %}
|
||||
<div class="btn-group btn-group-sm float-end" role="group">
|
||||
<button
|
||||
hx-get="{% url "character:armor_change" pk=character.pk %}?value=ko"
|
||||
|
@ -127,6 +134,7 @@
|
|||
disabled
|
||||
class="btn btn-outline-secondary"><i class="fa-solid fa-battery-full"></i></button>
|
||||
</div>
|
||||
{% endif %}
|
||||
</th>
|
||||
<td id="armor">
|
||||
{{ character.armor }}
|
||||
|
@ -135,6 +143,7 @@
|
|||
<tr>
|
||||
<th scope="row">
|
||||
Bouclier
|
||||
{% if character|managed_by:user %}
|
||||
<div class="btn-group btn-group-sm float-end" role="group">
|
||||
<button
|
||||
hx-get="{% url "character:shield_change" pk=character.pk %}?value=ko"
|
||||
|
@ -159,6 +168,7 @@
|
|||
disabled
|
||||
class="btn btn-outline-secondary"><i class="fa-solid fa-battery-full"></i></button>
|
||||
</div>
|
||||
{% endif %}
|
||||
</th>
|
||||
<td id="shield">
|
||||
{{ character.shield }}
|
||||
|
@ -167,6 +177,7 @@
|
|||
<tr>
|
||||
<th scope="row">
|
||||
Divers défense
|
||||
{% if character|managed_by:user %}
|
||||
<div class="btn-group btn-group-sm float-end" role="group">
|
||||
<button
|
||||
hx-get="{% url "character:defense_misc_change" pk=character.pk %}?value=ko"
|
||||
|
@ -191,6 +202,7 @@
|
|||
disabled
|
||||
class="btn btn-outline-secondary"><i class="fa-solid fa-battery-full"></i></button>
|
||||
</div>
|
||||
{% endif %}
|
||||
</th>
|
||||
<td id="defense-misc">
|
||||
{{ character.defense_misc }}
|
||||
|
@ -201,8 +213,10 @@
|
|||
<td data-bs-toggle="tooltip"
|
||||
data-bs-placement="left"
|
||||
data-bs-title="10 + armure + bouclier + mod. DEX + divers"
|
||||
{% if character|managed_by:user %}
|
||||
hx-get="{% url "character:get_defense" pk=character.pk %}"
|
||||
hx-trigger="update_defense from:#fight-table">
|
||||
hx-trigger="update_defense from:#fight-table"
|
||||
{% endif %}>
|
||||
{{ character.defense }}
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -218,6 +232,7 @@
|
|||
<tr>
|
||||
<th scope="row">
|
||||
Points de vie
|
||||
{% if character|managed_by:user %}
|
||||
<div class="btn-group btn-group-sm float-end" role="group">
|
||||
<button
|
||||
hx-get="{% url "character:health_change" pk=character.pk %}?value=ko"
|
||||
|
@ -244,12 +259,14 @@
|
|||
type="button"
|
||||
class="btn btn-outline-success"><i class="fa-solid fa-battery-full"></i></button>
|
||||
</div>
|
||||
{% endif %}
|
||||
</th>
|
||||
<td><span id="health-remaining">{{ character.health_remaining }}</span> / {{ character.health_max }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
Points de mana
|
||||
{% if character|managed_by:user %}
|
||||
<div class="btn-group btn-group-sm float-end" role="group">
|
||||
<button
|
||||
hx-get="{% url "character:mana_change" pk=character.pk %}?value=ko"
|
||||
|
@ -276,6 +293,7 @@
|
|||
type="button"
|
||||
class="btn btn-outline-success"><i class="fa-solid fa-battery-full"></i></button>
|
||||
</div>
|
||||
{% endif %}
|
||||
</th>
|
||||
<td data-bs-toggle="tooltip"
|
||||
data-bs-placement="left"
|
||||
|
@ -291,6 +309,7 @@
|
|||
<tr>
|
||||
<th scope="row">
|
||||
Points de récup.
|
||||
{% if character|managed_by:user %}
|
||||
<div class="btn-group btn-group-sm float-end" role="group">
|
||||
<button
|
||||
type="button"
|
||||
|
@ -313,6 +332,7 @@
|
|||
disabled
|
||||
class="btn btn-outline-secondary"><i class="fa-solid fa-battery-full"></i></button>
|
||||
</div>
|
||||
{% endif %}
|
||||
</th>
|
||||
<td>
|
||||
<span id="recovery-points-remaining">{{ character.recovery_points_remaining }}</span> / {{ character.recovery_points_max }}</td>
|
||||
|
@ -320,6 +340,7 @@
|
|||
<tr>
|
||||
<th scope="row">
|
||||
Points de chance
|
||||
{% if character|managed_by:user %}
|
||||
<div class="btn-group btn-group-sm float-end" role="group">
|
||||
<button
|
||||
type="button"
|
||||
|
@ -344,6 +365,7 @@
|
|||
type="button"
|
||||
class="btn btn-outline-success"><i class="fa-solid fa-battery-full"></i></button>
|
||||
</div>
|
||||
{% endif %}
|
||||
</th>
|
||||
<td data-bs-toggle="tooltip"
|
||||
data-bs-placement="left"
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
{% load character_extras %}
|
||||
<div class="card" id="damage-reduction">
|
||||
<h5 class="card-header">
|
||||
Réduction de dégâts
|
||||
{% if character|managed_by:user %}
|
||||
<a hx-get="{% url "character:damage_reduction_change" pk=character.pk %}"
|
||||
hx-target="#damage-reduction"
|
||||
hx-swap="outerHTML"
|
||||
|
@ -8,6 +10,7 @@
|
|||
>
|
||||
<i class="fa-solid fa-pen-to-square"></i> Edit
|
||||
</a>
|
||||
{% endif %}
|
||||
</h5>
|
||||
<div class="card-body">
|
||||
<p class="card-text">
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
{% load character_extras %}
|
||||
<div class="card" id="equipment">
|
||||
<h5 class="card-header">
|
||||
Équipement
|
||||
{% if character|managed_by:user %}
|
||||
<a hx-get="{% url "character:equipment_change" pk=character.pk %}"
|
||||
hx-target="#equipment"
|
||||
hx-swap="outerHTML"
|
||||
|
@ -8,6 +10,7 @@
|
|||
>
|
||||
<i class="fa-solid fa-pen-to-square"></i> Edit
|
||||
</a>
|
||||
{% endif %}
|
||||
</h5>
|
||||
<div class="card-body">
|
||||
<p class="card-text">
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
{% load character_extras %}
|
||||
<div class="mt-3" id="notes">
|
||||
<h2>
|
||||
Notes
|
||||
{% if character|managed_by:user %}
|
||||
<a hx-get="{% url "character:notes_change" pk=character.pk %}"
|
||||
hx-target="#notes"
|
||||
hx-swap="outerHTML"
|
||||
|
@ -8,6 +10,7 @@
|
|||
>
|
||||
<i class="fa-solid fa-pen-to-square"></i> Edit
|
||||
</a>
|
||||
{% endif %}
|
||||
</h2>
|
||||
{{ character.get_formatted_notes|safe }}
|
||||
</div>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
<div class="col-12 col-md-6 col-xl-4">
|
||||
<h5>
|
||||
{{ path.display_name }} ({{ path|max_rank:character }})
|
||||
{% if character|managed_by:user %}
|
||||
<div class="btn-group btn-group-sm">
|
||||
<button hx-get="{% url "character:remove_last_in_path" character_pk=character.pk path_pk=path.pk %}"
|
||||
hx-target="#paths-and-capabilities"
|
||||
|
@ -18,6 +19,7 @@
|
|||
</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</h5>
|
||||
{% if path.notes %}
|
||||
<div class="alert alert-primary">{{ path.notes }}</div>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
{% load character_extras %}
|
||||
{% load django_bootstrap5 %}
|
||||
<div id="paths-and-capabilities">
|
||||
{% if character|managed_by:user %}
|
||||
<form>
|
||||
{% csrf_token %}
|
||||
<div class="row">
|
||||
|
@ -18,6 +20,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{% endif %}
|
||||
<div class="row mt-2 gy-3">
|
||||
{% for path, capabilities in character.get_capabilities_by_path.items %}
|
||||
{% include "character/snippets/character_details/path.html" %}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
{% load character_extras %}
|
||||
<div class="col">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
|
@ -21,18 +22,22 @@
|
|||
{% endfor %}
|
||||
{% endwith %}
|
||||
</p>
|
||||
{% if character.player == user %}
|
||||
<div class="btn-group btn-group-sm">
|
||||
{% if character|managed_by:user %}
|
||||
<a href="{% url "character:view" pk=character.pk %}" class="btn btn-success">
|
||||
<i class="fa-solid fa-user"></i> Jouer
|
||||
<i class="fa-solid fa-user"></i> {% if character.player == user %}Jouer{% else %}Gérer{% endif %}
|
||||
</a>
|
||||
{% if party %}
|
||||
<a href="{% url "party:leave" pk=party.pk character_pk=character.pk %}" class="btn btn-warning">
|
||||
<i class="fa-solid fa-person-walking-arrow-right"></i> Quitter le groupe
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% else %}
|
||||
<a href="{% url "character:view" pk=character.pk %}" class="btn btn-primary">
|
||||
<i class="fa-solid fa-eye"></i> Observer
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue