Update notes

This commit is contained in:
Gabriel Augendre 2022-10-30 18:28:00 +01:00
parent 66c5b3e00b
commit 442d6a9781
5 changed files with 39 additions and 3 deletions

View file

@ -0,0 +1,10 @@
<p>
<a hx-get="{% url "character:notes_change" pk=character.pk %}"
hx-target="#notes"
hx-swap="innerHTML"
class="btn btn-primary btn-sm"
>
<i class="fa-solid fa-pen-to-square"></i> Edit
</a>
</p>
{{ character.notes|linebreaks }}

View file

@ -0,0 +1,13 @@
<form>
<p>
<a hx-post="{% url "character:notes_change" pk=character.pk %}"
hx-target="#notes"
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="notes" rows="10">{{ character.notes }}</textarea>
</form>

View file

@ -249,7 +249,7 @@
<div class="card"> <div class="card">
<h5 class="card-header">{{ path.display_name }}</h5> <h5 class="card-header">{{ path.display_name }}</h5>
{% if path.notes %} {% if path.notes %}
<div class="card-body">{{ path.notes }}</div> <div class="card-body text-bg-light">{{ path.notes }}</div>
{% endif %} {% endif %}
<ul class="list-group list-group-flush"> <ul class="list-group list-group-flush">
{% for capability in capabilities %} {% for capability in capabilities %}
@ -269,7 +269,7 @@
{% endfor %} {% endfor %}
</div> </div>
<h4 class="mt-3">Notes</h4> <h4 class="mt-3">Notes</h4>
<div class="row"> <div class="row" id="notes">
{{ character.notes|linebreaks }} {% include "character/notes_display.html" %}
</div> </div>
{% endblock %} {% endblock %}

View file

@ -7,4 +7,5 @@ urlpatterns = [
path("<int:pk>/", views.character_view, name="view"), path("<int:pk>/", views.character_view, name="view"),
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"),
] ]

View file

@ -40,6 +40,18 @@ 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":