Allow updating damage reduction

This commit is contained in:
Gabriel Augendre 2022-10-30 23:44:02 +01:00
parent a03cda1771
commit 3a949fe2d7
5 changed files with 50 additions and 12 deletions

View file

@ -0,0 +1,17 @@
<div class="card" id="damage-reduction">
<h5 class="card-header">
Réduction de dégâts
<a hx-get="{% url "character:damage_reduction_change" pk=character.pk %}"
hx-target="#damage-reduction"
hx-swap="outerHTML"
class="btn btn-primary btn-sm"
>
<i class="fa-solid fa-pen-to-square"></i> Edit
</a>
</h5>
<div class="card-body">
<p class="card-text">
{{ character.damage_reduction|linebreaksbr|default:"Rien ici..." }}
</p>
</div>
</div>

View file

@ -0,0 +1,18 @@
<form id="damage-reduction">
<div class="card">
<h5 class="card-header">
Réduction de dégâts
<a hx-post="{% url "character:damage_reduction_change" pk=character.pk %}"
hx-target="#damage-reduction"
hx-swap="outerHTML"
class="btn btn-primary btn-sm"
>
<i class="fa-solid fa-save"></i> Save
</a>
</h5>
<div class="card-body">
{% csrf_token %}
<textarea class="form-control" name="damage_reduction" rows="2">{{ character.damage_reduction }}</textarea>
</div>
</div>
</form>

View file

@ -317,7 +317,7 @@
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-6 mb-3"> <div class="col-md-6 col-lg-4 mb-3">
<div class="card"> <div class="card">
<h5 class="card-header">{{ character.racial_capability.name }}</h5> <h5 class="card-header">{{ character.racial_capability.name }}</h5>
<div class="card-body"> <div class="card-body">
@ -325,17 +325,10 @@
</div> </div>
</div> </div>
</div> </div>
<div class="col-md-6 mb-3"> <div class="col-md-6 col-lg-4 mb-3">
<div class="card"> {% include "character/damage_reduction_display.html" %}
<h5 class="card-header">Réduction de dégâts</h5>
<div class="card-body">
<p class="card-text">{{ character.damage_reduction|linebreaksbr|default:"Rien ici..." }}</p>
</div> </div>
</div> <div class="col-md-12 col-lg-4 mb-3">
</div>
</div>
<div class="row">
<div class="col">
<div class="card"> <div class="card">
<h5 class="card-header">Équipement</h5> <h5 class="card-header">Équipement</h5>
<div class="card-body" id="equipment"> <div class="card-body" id="equipment">
@ -350,7 +343,7 @@
</div> </div>
</div> </div>
</div> </div>
<h4 class="mt-3">Voies & Capacités</h4> <h4>Voies & Capacités</h4>
<div class="row gy-3"> <div class="row gy-3">
{% for path, capabilities in character.get_capabilities_by_path.items %} {% for path, capabilities in character.get_capabilities_by_path.items %}
<div class="col-xl-3 col-md-6"> <div class="col-xl-3 col-md-6">

View file

@ -29,4 +29,9 @@ urlpatterns = [
views.character_equipment_change, views.character_equipment_change,
name="equipment_change", name="equipment_change",
), ),
path(
"<int:pk>/damage_reduction_change",
views.character_damage_reduction_change,
name="damage_reduction_change",
),
] ]

View file

@ -115,6 +115,11 @@ def character_equipment_change(request: WSGIRequest, pk: int) -> HttpResponse:
return update_text_field(request, pk, "equipment") return update_text_field(request, pk, "equipment")
@login_required
def character_damage_reduction_change(request: WSGIRequest, pk: int) -> HttpResponse:
return update_text_field(request, pk, "damage_reduction")
def update_text_field(request, pk, field): def update_text_field(request, pk, field):
character = get_object_or_404(Character.objects.only(field), pk=pk) character = get_object_or_404(Character.objects.only(field), pk=pk)
context = {"character": character} context = {"character": character}