Refactor template snippets

This commit is contained in:
Gabriel Augendre 2022-11-02 22:52:36 +01:00
parent cb787b7ed5
commit a8f7d04bdf
15 changed files with 55 additions and 18 deletions

View file

@ -10,7 +10,7 @@
</a> </a>
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 row-cols-lg-4 g-4"> <div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 row-cols-lg-4 g-4">
{% for character in characters %} {% for character in characters %}
{% include "character/character_card.html" %} {% include "character/snippets/characters_list/character_card.html" %}
{% endfor %} {% endfor %}
</div> </div>
{% endblock %} {% endblock %}

View file

@ -24,7 +24,7 @@
{% endif %} {% endif %}
<div class="accordion capabilities"> <div class="accordion capabilities">
{% for capability in capabilities %} {% for capability in capabilities %}
{% include "character/capability.html" %} {% include "character/snippets/character_details/capability.html" %}
{% endfor %} {% endfor %}
</div> </div>
</div> </div>

View file

@ -20,7 +20,7 @@
</form> </form>
<div class="row mt-2 gy-3"> <div class="row mt-2 gy-3">
{% for path, capabilities in character.get_capabilities_by_path.items %} {% for path, capabilities in character.get_capabilities_by_path.items %}
{% include "character/path.html" %} {% include "character/snippets/character_details/path.html" %}
{% endfor %} {% endfor %}
</div> </div>
</div> </div>

View file

@ -21,7 +21,7 @@
{{ character.race.name }} {{ character.profile.name }} niv. {{ character.level }}<br> {{ character.race.name }} {{ character.profile.name }} niv. {{ character.level }}<br>
{{ character.get_gender_display }}, {{ character.age }} ans, {{ character.height_m }}m, {{ character.weight }}kg (IMC: {{ character.imc|floatformat }}) {{ character.get_gender_display }}, {{ character.age }} ans, {{ character.height_m }}m, {{ character.weight }}kg (IMC: {{ character.imc|floatformat }})
</p> </p>
{% include "character/states.html" %} {% include "character/snippets/character_details/states.html" %}
<div class="row"> <div class="row">
<div class="col-sm-12 col-md-6 col-lg-6 col-xl"> <div class="col-sm-12 col-md-6 col-lg-6 col-xl">
<table id="fight-table" class="table table-hover table-sm"> <table id="fight-table" class="table table-hover table-sm">
@ -443,13 +443,13 @@
</div> </div>
</div> </div>
<div class="col-md-6 col-lg-4 mb-3"> <div class="col-md-6 col-lg-4 mb-3">
{% include "character/damage_reduction_display.html" %} {% include "character/snippets/character_details/damage_reduction_display.html" %}
</div> </div>
<div class="col-md-12 col-lg-4 mb-3"> <div class="col-md-12 col-lg-4 mb-3">
{% include "character/equipment_display.html" %} {% include "character/snippets/character_details/equipment_display.html" %}
</div> </div>
</div> </div>
<h2>Voies & Capacités</h2> <h2>Voies & Capacités</h2>
{% include "character/paths_and_capabilities.html" %} {% include "character/snippets/character_details/paths_and_capabilities.html" %}
{% include "character/notes_display.html" %} {% include "character/snippets/character_details/notes_display.html" %}
{% endblock %} {% endblock %}

View file

@ -54,7 +54,11 @@ def add_path(request, pk: int):
context["add_path_form"] = AddPathForm(character) context["add_path_form"] = AddPathForm(character)
else: else:
context["add_path_form"] = form 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 @login_required
@ -212,14 +216,26 @@ def character_equipment_change(request, pk: int):
) )
context = {"character": character} context = {"character": character}
if request.method == "GET": 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) form = EquipmentForm(request.POST, instance=character)
if form.is_valid(): if form.is_valid():
form.save() form.save()
return render(request, f"character/{field}_display.html", context) return render(
request,
f"character/snippets/character_details/{field}_display.html",
context,
)
else: else:
context["errors"] = form.errors 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 @login_required
@ -233,10 +249,16 @@ def update_text_field(request, pk, field):
) )
context = {"character": character} context = {"character": character}
if request.method == "GET": 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)) setattr(character, field, request.POST.get(field))
character.save(update_fields=[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 @login_required
@ -251,7 +273,11 @@ def add_next_in_path(request, character_pk: int, path_pk: int):
"character": character, "character": character,
"add_path_form": AddPathForm(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 @login_required
@ -268,7 +294,11 @@ def remove_last_in_path(request, character_pk: int, path_pk: int):
"character": character, "character": character,
"add_path_form": AddPathForm(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 @login_required
@ -279,7 +309,9 @@ def remove_state(request, pk: int, state_pk: int):
state = get_object_or_404(HarmfulState, pk=state_pk) state = get_object_or_404(HarmfulState, pk=state_pk)
character.states.remove(state) character.states.remove(state)
context = {"character": character, "all_states": HarmfulState.objects.all()} 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", {}) 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) state = get_object_or_404(HarmfulState, pk=state_pk)
character.states.add(state) character.states.add(state)
context = {"character": character, "all_states": HarmfulState.objects.all()} 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", {}) return trigger_client_event(response, "refresh_tooltips", {})

View file

@ -9,6 +9,9 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" aria-current="page" href="{% url "character:list" %}">Mes perso</a> <a class="nav-link" aria-current="page" href="{% url "character:list" %}">Mes perso</a>
</li> </li>
<li class="nav-item">
<a class="nav-link" aria-current="page" href="{% url "character:list" %}">Mes groupes</a>
</li>
</ul> </ul>
<ul class="navbar-nav"> <ul class="navbar-nav">
{% if user.is_authenticated %} {% if user.is_authenticated %}