mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-11-22 14:38:03 +01:00
Allow updating money with equipment
This commit is contained in:
parent
1479a4fe53
commit
4ee558b12d
3 changed files with 45 additions and 6 deletions
9
src/character/forms.py
Normal file
9
src/character/forms.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from django import forms
|
||||
|
||||
from character.models import Character
|
||||
|
||||
|
||||
class EquipmentForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Character
|
||||
fields = ["equipment", "money_pp", "money_po", "money_pa", "money_pc"]
|
|
@ -1,5 +1,5 @@
|
|||
<form id="equipment">
|
||||
<div class="card">
|
||||
<div class="card {% if errors %}border-danger{% endif %}">
|
||||
<h5 class="card-header">
|
||||
Équipement
|
||||
<a hx-post="{% url "character:equipment_change" pk=character.pk %}"
|
||||
|
@ -10,15 +10,33 @@
|
|||
<i class="fa-solid fa-save"></i> Save
|
||||
</a>
|
||||
</h5>
|
||||
|
||||
{% if errors %}
|
||||
<div class="card-body text-bg-danger">Errors:{{ errors }}</div>
|
||||
{% endif %}
|
||||
<div class="card-body">
|
||||
{% csrf_token %}
|
||||
<textarea class="form-control" name="equipment" rows="10">{{ character.equipment }}</textarea>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
{{ character.money_pp }} pp,
|
||||
{{ character.money_po }} po,
|
||||
{{ character.money_pa }} pa,
|
||||
{{ character.money_pc }} pc
|
||||
<div class="row g-1">
|
||||
<div class="col input-group input-group-sm">
|
||||
<input type="number" min="0" class="form-control" name="money_pp" value="{{ character.money_pp }}">
|
||||
<span class="input-group-text">pp</span>
|
||||
</div>
|
||||
<div class="col input-group input-group-sm">
|
||||
<input type="number" min="0" class="form-control" name="money_po" value="{{ character.money_po }}">
|
||||
<span class="input-group-text">po</span>
|
||||
</div>
|
||||
<div class="col input-group input-group-sm">
|
||||
<input type="number" min="0" class="form-control" name="money_pa" value="{{ character.money_pa }}">
|
||||
<span class="input-group-text">pa</span>
|
||||
</div>
|
||||
<div class="col input-group input-group-sm">
|
||||
<input type="number" min="0" class="form-control" name="money_pc" value="{{ character.money_pc }}">
|
||||
<span class="input-group-text">pc</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -4,6 +4,7 @@ from django.http import HttpResponse
|
|||
from django.shortcuts import get_object_or_404, render
|
||||
from django_htmx.http import trigger_client_event
|
||||
|
||||
from character.forms import EquipmentForm
|
||||
from character.models import Character
|
||||
|
||||
|
||||
|
@ -112,7 +113,18 @@ def character_notes_change(request: WSGIRequest, pk: int) -> HttpResponse:
|
|||
|
||||
@login_required
|
||||
def character_equipment_change(request: WSGIRequest, pk: int) -> HttpResponse:
|
||||
return update_text_field(request, pk, "equipment")
|
||||
field = "equipment"
|
||||
character = get_object_or_404(Character.objects.only(field), pk=pk)
|
||||
context = {"character": character}
|
||||
if request.method == "GET":
|
||||
return render(request, f"character/{field}_update.html", context)
|
||||
form = EquipmentForm(request.POST, instance=character)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return render(request, f"character/{field}_display.html", context)
|
||||
else:
|
||||
context["errors"] = form.errors
|
||||
return render(request, f"character/{field}_update.html", context)
|
||||
|
||||
|
||||
@login_required
|
||||
|
|
Loading…
Reference in a new issue