mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-11-04 22:03:56 +01:00
Update notes
This commit is contained in:
parent
66c5b3e00b
commit
442d6a9781
5 changed files with 39 additions and 3 deletions
10
src/character/templates/character/notes_display.html
Normal file
10
src/character/templates/character/notes_display.html
Normal 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 }}
|
13
src/character/templates/character/notes_update.html
Normal file
13
src/character/templates/character/notes_update.html
Normal 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>
|
|
@ -249,7 +249,7 @@
|
|||
<div class="card">
|
||||
<h5 class="card-header">{{ path.display_name }}</h5>
|
||||
{% if path.notes %}
|
||||
<div class="card-body">{{ path.notes }}</div>
|
||||
<div class="card-body text-bg-light">{{ path.notes }}</div>
|
||||
{% endif %}
|
||||
<ul class="list-group list-group-flush">
|
||||
{% for capability in capabilities %}
|
||||
|
@ -269,7 +269,7 @@
|
|||
{% endfor %}
|
||||
</div>
|
||||
<h4 class="mt-3">Notes</h4>
|
||||
<div class="row">
|
||||
{{ character.notes|linebreaks }}
|
||||
<div class="row" id="notes">
|
||||
{% include "character/notes_display.html" %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -7,4 +7,5 @@ urlpatterns = [
|
|||
path("<int:pk>/", views.character_view, name="view"),
|
||||
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"),
|
||||
]
|
||||
|
|
|
@ -40,6 +40,18 @@ 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":
|
||||
|
|
Loading…
Reference in a new issue