From a8f7d04bdfa84a1abaa28c784f8549db94a92a54 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Wed, 2 Nov 2022 22:52:36 +0100 Subject: [PATCH] Refactor template snippets --- src/character/templates/character/list.html | 2 +- .../character_details}/capability.html | 0 .../damage_reduction_display.html | 0 .../damage_reduction_update.html | 0 .../character_details}/equipment_display.html | 0 .../character_details}/equipment_update.html | 0 .../character_details}/notes_display.html | 0 .../character_details}/notes_update.html | 0 .../character_details}/path.html | 2 +- .../paths_and_capabilities.html | 2 +- .../character_details}/states.html | 0 .../characters_list}/character_card.html | 0 src/character/templates/character/view.html | 10 ++-- src/character/views.py | 54 +++++++++++++++---- src/common/templates/common/navbar.html | 3 ++ 15 files changed, 55 insertions(+), 18 deletions(-) rename src/character/templates/character/{ => snippets/character_details}/capability.html (100%) rename src/character/templates/character/{ => snippets/character_details}/damage_reduction_display.html (100%) rename src/character/templates/character/{ => snippets/character_details}/damage_reduction_update.html (100%) rename src/character/templates/character/{ => snippets/character_details}/equipment_display.html (100%) rename src/character/templates/character/{ => snippets/character_details}/equipment_update.html (100%) rename src/character/templates/character/{ => snippets/character_details}/notes_display.html (100%) rename src/character/templates/character/{ => snippets/character_details}/notes_update.html (100%) rename src/character/templates/character/{ => snippets/character_details}/path.html (93%) rename src/character/templates/character/{ => snippets/character_details}/paths_and_capabilities.html (92%) rename src/character/templates/character/{ => snippets/character_details}/states.html (100%) rename src/character/templates/character/{ => snippets/characters_list}/character_card.html (100%) diff --git a/src/character/templates/character/list.html b/src/character/templates/character/list.html index 49a3e25..98e4b5f 100644 --- a/src/character/templates/character/list.html +++ b/src/character/templates/character/list.html @@ -10,7 +10,7 @@
{% for character in characters %} - {% include "character/character_card.html" %} + {% include "character/snippets/characters_list/character_card.html" %} {% endfor %}
{% endblock %} diff --git a/src/character/templates/character/capability.html b/src/character/templates/character/snippets/character_details/capability.html similarity index 100% rename from src/character/templates/character/capability.html rename to src/character/templates/character/snippets/character_details/capability.html diff --git a/src/character/templates/character/damage_reduction_display.html b/src/character/templates/character/snippets/character_details/damage_reduction_display.html similarity index 100% rename from src/character/templates/character/damage_reduction_display.html rename to src/character/templates/character/snippets/character_details/damage_reduction_display.html diff --git a/src/character/templates/character/damage_reduction_update.html b/src/character/templates/character/snippets/character_details/damage_reduction_update.html similarity index 100% rename from src/character/templates/character/damage_reduction_update.html rename to src/character/templates/character/snippets/character_details/damage_reduction_update.html diff --git a/src/character/templates/character/equipment_display.html b/src/character/templates/character/snippets/character_details/equipment_display.html similarity index 100% rename from src/character/templates/character/equipment_display.html rename to src/character/templates/character/snippets/character_details/equipment_display.html diff --git a/src/character/templates/character/equipment_update.html b/src/character/templates/character/snippets/character_details/equipment_update.html similarity index 100% rename from src/character/templates/character/equipment_update.html rename to src/character/templates/character/snippets/character_details/equipment_update.html diff --git a/src/character/templates/character/notes_display.html b/src/character/templates/character/snippets/character_details/notes_display.html similarity index 100% rename from src/character/templates/character/notes_display.html rename to src/character/templates/character/snippets/character_details/notes_display.html diff --git a/src/character/templates/character/notes_update.html b/src/character/templates/character/snippets/character_details/notes_update.html similarity index 100% rename from src/character/templates/character/notes_update.html rename to src/character/templates/character/snippets/character_details/notes_update.html diff --git a/src/character/templates/character/path.html b/src/character/templates/character/snippets/character_details/path.html similarity index 93% rename from src/character/templates/character/path.html rename to src/character/templates/character/snippets/character_details/path.html index d80ad24..ec85627 100644 --- a/src/character/templates/character/path.html +++ b/src/character/templates/character/snippets/character_details/path.html @@ -24,7 +24,7 @@ {% endif %}
{% for capability in capabilities %} - {% include "character/capability.html" %} + {% include "character/snippets/character_details/capability.html" %} {% endfor %}
diff --git a/src/character/templates/character/paths_and_capabilities.html b/src/character/templates/character/snippets/character_details/paths_and_capabilities.html similarity index 92% rename from src/character/templates/character/paths_and_capabilities.html rename to src/character/templates/character/snippets/character_details/paths_and_capabilities.html index 795c8a1..647f305 100644 --- a/src/character/templates/character/paths_and_capabilities.html +++ b/src/character/templates/character/snippets/character_details/paths_and_capabilities.html @@ -20,7 +20,7 @@
{% for path, capabilities in character.get_capabilities_by_path.items %} - {% include "character/path.html" %} + {% include "character/snippets/character_details/path.html" %} {% endfor %}
diff --git a/src/character/templates/character/states.html b/src/character/templates/character/snippets/character_details/states.html similarity index 100% rename from src/character/templates/character/states.html rename to src/character/templates/character/snippets/character_details/states.html diff --git a/src/character/templates/character/character_card.html b/src/character/templates/character/snippets/characters_list/character_card.html similarity index 100% rename from src/character/templates/character/character_card.html rename to src/character/templates/character/snippets/characters_list/character_card.html diff --git a/src/character/templates/character/view.html b/src/character/templates/character/view.html index e6c6dc8..208dadf 100644 --- a/src/character/templates/character/view.html +++ b/src/character/templates/character/view.html @@ -21,7 +21,7 @@ {{ character.race.name }} {{ character.profile.name }} niv. {{ character.level }}
{{ character.get_gender_display }}, {{ character.age }} ans, {{ character.height_m }}m, {{ character.weight }}kg (IMC: {{ character.imc|floatformat }})

- {% include "character/states.html" %} + {% include "character/snippets/character_details/states.html" %}
@@ -443,13 +443,13 @@
- {% include "character/damage_reduction_display.html" %} + {% include "character/snippets/character_details/damage_reduction_display.html" %}
- {% include "character/equipment_display.html" %} + {% include "character/snippets/character_details/equipment_display.html" %}

Voies & Capacités

- {% include "character/paths_and_capabilities.html" %} - {% include "character/notes_display.html" %} + {% include "character/snippets/character_details/paths_and_capabilities.html" %} + {% include "character/snippets/character_details/notes_display.html" %} {% endblock %} diff --git a/src/character/views.py b/src/character/views.py index 243f2ee..0bb6dfe 100644 --- a/src/character/views.py +++ b/src/character/views.py @@ -54,7 +54,11 @@ def add_path(request, pk: int): context["add_path_form"] = AddPathForm(character) else: context["add_path_form"] = form - return render(request, "character/paths_and_capabilities.html", context) + return render( + request, + "character/snippets/character_details/paths_and_capabilities.html", + context, + ) @login_required @@ -212,14 +216,26 @@ def character_equipment_change(request, pk: int): ) context = {"character": character} if request.method == "GET": - return render(request, f"character/{field}_update.html", context) + return render( + request, + f"character/snippets/character_details/{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) + return render( + request, + f"character/snippets/character_details/{field}_display.html", + context, + ) else: context["errors"] = form.errors - return render(request, f"character/{field}_update.html", context) + return render( + request, + f"character/snippets/character_details/{field}_update.html", + context, + ) @login_required @@ -233,10 +249,16 @@ def update_text_field(request, pk, field): ) context = {"character": character} if request.method == "GET": - return render(request, f"character/{field}_update.html", context) + return render( + request, + f"character/snippets/character_details/{field}_update.html", + context, + ) setattr(character, field, request.POST.get(field)) character.save(update_fields=[field]) - return render(request, f"character/{field}_display.html", context) + return render( + request, f"character/snippets/character_details/{field}_display.html", context + ) @login_required @@ -251,7 +273,11 @@ def add_next_in_path(request, character_pk: int, path_pk: int): "character": character, "add_path_form": AddPathForm(character), } - return render(request, "character/paths_and_capabilities.html", context) + return render( + request, + "character/snippets/character_details/paths_and_capabilities.html", + context, + ) @login_required @@ -268,7 +294,11 @@ def remove_last_in_path(request, character_pk: int, path_pk: int): "character": character, "add_path_form": AddPathForm(character), } - return render(request, "character/paths_and_capabilities.html", context) + return render( + request, + "character/snippets/character_details/paths_and_capabilities.html", + context, + ) @login_required @@ -279,7 +309,9 @@ def remove_state(request, pk: int, state_pk: int): state = get_object_or_404(HarmfulState, pk=state_pk) character.states.remove(state) context = {"character": character, "all_states": HarmfulState.objects.all()} - response = render(request, "character/states.html", context) + response = render( + request, "character/snippets/character_details/states.html", context + ) return trigger_client_event(response, "refresh_tooltips", {}) @@ -291,5 +323,7 @@ def add_state(request, pk: int, state_pk: int): state = get_object_or_404(HarmfulState, pk=state_pk) character.states.add(state) context = {"character": character, "all_states": HarmfulState.objects.all()} - response = render(request, "character/states.html", context) + response = render( + request, "character/snippets/character_details/states.html", context + ) return trigger_client_event(response, "refresh_tooltips", {}) diff --git a/src/common/templates/common/navbar.html b/src/common/templates/common/navbar.html index 8f6426d..48b33e7 100644 --- a/src/common/templates/common/navbar.html +++ b/src/common/templates/common/navbar.html @@ -9,6 +9,9 @@ +