mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-11-04 22:03:56 +01:00
Improve paths update
This commit is contained in:
parent
0287536ba8
commit
41417e660c
4 changed files with 66 additions and 25 deletions
30
src/character/templates/character/path.html
Normal file
30
src/character/templates/character/path.html
Normal file
|
@ -0,0 +1,30 @@
|
|||
{% load character_extras %}
|
||||
<div class="col-xl-3 col-md-6" data-path-id="{{ path.pk }}">
|
||||
<div class="card">
|
||||
<h5 class="card-header">
|
||||
{{ path.display_name }}
|
||||
{% if path|has_next_capability:character %}
|
||||
<button hx-get="{% url "character:add_next_in_path" character_pk=character.pk path_pk=path.pk %}"
|
||||
hx-target="[data-path-id='{{ path.pk }}']"
|
||||
hx-swap="outerHTML"
|
||||
class="btn btn-sm btn-primary">
|
||||
<i class="fa-solid fa-plus"></i>
|
||||
</button>
|
||||
{% endif %}
|
||||
<button hx-get="{% url "character:remove_last_in_path" character_pk=character.pk path_pk=path.pk %}"
|
||||
hx-target="[data-path-id='{{ path.pk }}']"
|
||||
hx-swap="outerHTML"
|
||||
class="btn btn-sm btn-primary">
|
||||
<i class="fa-solid fa-minus"></i>
|
||||
</button>
|
||||
</h5>
|
||||
{% if path.notes %}
|
||||
<div class="card-body text-bg-light">{{ path.notes }}</div>
|
||||
{% endif %}
|
||||
<ul class="list-group list-group-flush capabilities">
|
||||
{% for capability in capabilities %}
|
||||
{% include "character/capability.html" %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
|
@ -338,29 +338,7 @@
|
|||
<h2>Voies & Capacités</h2>
|
||||
<div class="row gy-3">
|
||||
{% for path, capabilities in character.get_capabilities_by_path.items %}
|
||||
<div class="col-xl-3 col-md-6">
|
||||
<div class="card" data-path-id="{{ path.pk }}">
|
||||
<h5 class="card-header">{{ path.display_name }}</h5>
|
||||
{% if path.notes %}
|
||||
<div class="card-body text-bg-light">{{ path.notes }}</div>
|
||||
{% endif %}
|
||||
<ul class="list-group list-group-flush capabilities">
|
||||
{% for capability in capabilities %}
|
||||
{% include "character/capability.html" %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% if path|has_next_capability:character %}
|
||||
<div class="card-body">
|
||||
<button hx-get="{% url "character:add_next_in_path" character_pk=character.pk path_pk=path.pk %}"
|
||||
hx-target="[data-path-id='{{ path.pk }}'] .capabilities"
|
||||
hx-swap="beforeend"
|
||||
class="btn btn-primary">
|
||||
Next
|
||||
</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% include "character/path.html" %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% include "character/notes_display.html" %}
|
||||
|
|
|
@ -43,4 +43,9 @@ urlpatterns = [
|
|||
views.add_next_in_path,
|
||||
name="add_next_in_path",
|
||||
),
|
||||
path(
|
||||
"<int:character_pk>/remove_last_in_path/<int:path_pk>/",
|
||||
views.remove_last_in_path,
|
||||
name="remove_last_in_path",
|
||||
),
|
||||
]
|
||||
|
|
|
@ -4,7 +4,7 @@ from django.shortcuts import get_object_or_404, redirect, render
|
|||
from django_htmx.http import trigger_client_event
|
||||
|
||||
from character.forms import EquipmentForm
|
||||
from character.models import Character, Path
|
||||
from character.models import Capability, Character, Path
|
||||
|
||||
|
||||
@login_required
|
||||
|
@ -177,4 +177,32 @@ def add_next_in_path(request, character_pk: int, path_pk: int):
|
|||
path = get_object_or_404(Path, pk=path_pk)
|
||||
capability = path.get_next_capability(character)
|
||||
character.capabilities.add(capability)
|
||||
return render(request, "character/capability.html", {"capability": capability})
|
||||
context = {
|
||||
"capabilities": character.capabilities.filter(path=path).order_by("rank"),
|
||||
"path": path,
|
||||
"character": character,
|
||||
}
|
||||
return render(request, "character/path.html", context)
|
||||
|
||||
|
||||
@login_required
|
||||
def remove_last_in_path(request, character_pk: int, path_pk: int):
|
||||
character = get_object_or_404(
|
||||
Character.objects.filter(player=request.user), pk=character_pk
|
||||
)
|
||||
path = get_object_or_404(Path, pk=path_pk)
|
||||
last_rank = max(
|
||||
character.capabilities.filter(path=path).values_list("rank", flat=True)
|
||||
)
|
||||
cap = Capability.objects.get(path=path, rank=last_rank)
|
||||
character.capabilities.remove(cap)
|
||||
capabilities = character.capabilities.filter(path=path).order_by("rank")
|
||||
if len(capabilities) == 0:
|
||||
return HttpResponse()
|
||||
|
||||
context = {
|
||||
"capabilities": capabilities,
|
||||
"path": path,
|
||||
"character": character,
|
||||
}
|
||||
return render(request, "character/path.html", context)
|
||||
|
|
Loading…
Reference in a new issue