mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-12-22 22:01:48 +01:00
Update equipment
This commit is contained in:
parent
442d6a9781
commit
9b627b3186
5 changed files with 56 additions and 14 deletions
12
src/character/templates/character/equipment_display.html
Normal file
12
src/character/templates/character/equipment_display.html
Normal 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>
|
13
src/character/templates/character/equipment_update.html
Normal file
13
src/character/templates/character/equipment_update.html
Normal 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>
|
|
@ -230,8 +230,8 @@
|
|||
<div class="col">
|
||||
<div class="card">
|
||||
<h5 class="card-header">Équipement</h5>
|
||||
<div class="card-body">
|
||||
<p class="card-text">{{ character.equipment|linebreaksbr|default:"Rien ici..." }}</p>
|
||||
<div class="card-body" id="equipment">
|
||||
{% include "character/equipment_display.html" %}
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
{{ character.money_pp }} pp,
|
||||
|
|
|
@ -8,4 +8,9 @@ urlpatterns = [
|
|||
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>/notes_change", views.character_notes_change, name="notes_change"),
|
||||
path(
|
||||
"<int:pk>/equipment_change",
|
||||
views.character_equipment_change,
|
||||
name="equipment_change",
|
||||
),
|
||||
]
|
||||
|
|
|
@ -40,18 +40,6 @@ def character_mana_change(request: WSGIRequest, pk: int) -> HttpResponse:
|
|||
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):
|
||||
value = request.GET.get("value")
|
||||
if value == "ko":
|
||||
|
@ -64,3 +52,27 @@ def get_updated_value(max_value, request):
|
|||
value = min([max_value, value])
|
||||
value = max([0, 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)
|
||||
|
|
Loading…
Reference in a new issue