Update equipment

This commit is contained in:
Gabriel Augendre 2022-10-30 18:33:30 +01:00
parent 442d6a9781
commit 9b627b3186
5 changed files with 56 additions and 14 deletions

View file

@ -0,0 +1,12 @@
<p class="card-text">
<a hx-get="{% url "character:equipment_change" pk=character.pk %}"
hx-target="#equipment"
hx-swap="innerHTML"
class="btn btn-primary btn-sm"
>
<i class="fa-solid fa-pen-to-square"></i> Edit
</a>
</p>
<p class="card-text">
{{ character.equipment|linebreaksbr|default:"Rien ici..." }}
</p>

View file

@ -0,0 +1,13 @@
<form>
<p>
<a hx-post="{% url "character:equipment_change" pk=character.pk %}"
hx-target="#equipment"
hx-swap="innerHTML"
class="btn btn-primary btn-sm"
>
<i class="fa-solid fa-save"></i> Save
</a>
</p>
{% csrf_token %}
<textarea class="form-control" name="equipment" rows="10">{{ character.equipment }}</textarea>
</form>

View file

@ -230,8 +230,8 @@
<div class="col"> <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"> <div class="card-body" id="equipment">
<p class="card-text">{{ character.equipment|linebreaksbr|default:"Rien ici..." }}</p> {% include "character/equipment_display.html" %}
</div> </div>
<div class="card-footer"> <div class="card-footer">
{{ character.money_pp }} pp, {{ character.money_pp }} pp,

View file

@ -8,4 +8,9 @@ urlpatterns = [
path("<int:pk>/health_change", views.character_health_change, name="health_change"), path("<int:pk>/health_change", views.character_health_change, name="health_change"),
path("<int:pk>/mana_change", views.character_mana_change, name="mana_change"), path("<int:pk>/mana_change", views.character_mana_change, name="mana_change"),
path("<int:pk>/notes_change", views.character_notes_change, name="notes_change"), path("<int:pk>/notes_change", views.character_notes_change, name="notes_change"),
path(
"<int:pk>/equipment_change",
views.character_equipment_change,
name="equipment_change",
),
] ]

View file

@ -40,18 +40,6 @@ def character_mana_change(request: WSGIRequest, pk: int) -> HttpResponse:
return HttpResponse(character.mana_remaining) return HttpResponse(character.mana_remaining)
@login_required
def character_notes_change(request: WSGIRequest, pk: int) -> HttpResponse:
character = get_object_or_404(Character.objects.only("notes"), pk=pk)
context = {"character": character}
if request.method == "GET":
return render(request, "character/notes_update.html", context)
character.notes = request.POST.get("notes")
character.save()
return render(request, "character/notes_display.html", context)
def get_updated_value(max_value, request): def get_updated_value(max_value, request):
value = request.GET.get("value") value = request.GET.get("value")
if value == "ko": if value == "ko":
@ -64,3 +52,27 @@ def get_updated_value(max_value, request):
value = min([max_value, value]) value = min([max_value, value])
value = max([0, value]) value = max([0, value])
return value return value
@login_required
def character_notes_change(request: WSGIRequest, pk: int) -> HttpResponse:
character = get_object_or_404(Character.objects.only("notes"), pk=pk)
context = {"character": character}
if request.method == "GET":
return render(request, "character/notes_update.html", context)
character.notes = request.POST.get("notes")
character.save()
return render(request, "character/notes_display.html", context)
@login_required
def character_equipment_change(request: WSGIRequest, pk: int) -> HttpResponse:
character = get_object_or_404(Character.objects.only("equipment"), pk=pk)
context = {"character": character}
if request.method == "GET":
return render(request, "character/equipment_update.html", context)
character.equipment = request.POST.get("equipment")
character.save()
return render(request, "character/equipment_display.html", context)