diff --git a/src/character/templates/character/path.html b/src/character/templates/character/path.html
new file mode 100644
index 0000000..a8575f0
--- /dev/null
+++ b/src/character/templates/character/path.html
@@ -0,0 +1,30 @@
+{% load character_extras %}
+
+
+
+ {% if path.notes %}
+
{{ path.notes }}
+ {% endif %}
+
+ {% for capability in capabilities %}
+ {% include "character/capability.html" %}
+ {% endfor %}
+
+
+
diff --git a/src/character/templates/character/view.html b/src/character/templates/character/view.html
index a62c550..850ae1d 100644
--- a/src/character/templates/character/view.html
+++ b/src/character/templates/character/view.html
@@ -338,29 +338,7 @@
Voies & Capacités
{% for path, capabilities in character.get_capabilities_by_path.items %}
-
-
-
- {% if path.notes %}
-
{{ path.notes }}
- {% endif %}
-
- {% for capability in capabilities %}
- {% include "character/capability.html" %}
- {% endfor %}
-
- {% if path|has_next_capability:character %}
-
-
-
- {% endif %}
-
-
+ {% include "character/path.html" %}
{% endfor %}
{% include "character/notes_display.html" %}
diff --git a/src/character/urls.py b/src/character/urls.py
index 85a42d3..e2287de 100644
--- a/src/character/urls.py
+++ b/src/character/urls.py
@@ -43,4 +43,9 @@ urlpatterns = [
views.add_next_in_path,
name="add_next_in_path",
),
+ path(
+ "/remove_last_in_path//",
+ views.remove_last_in_path,
+ name="remove_last_in_path",
+ ),
]
diff --git a/src/character/views.py b/src/character/views.py
index a3d8b1c..3d956ca 100644
--- a/src/character/views.py
+++ b/src/character/views.py
@@ -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)