diff --git a/src/character/templates/character/character_card.html b/src/character/templates/character/character_card.html new file mode 100644 index 0000000..4835854 --- /dev/null +++ b/src/character/templates/character/character_card.html @@ -0,0 +1,16 @@ +
+
+
+
+ + {{ character.name }} + +
+

+ {{ character.race.name }} {{ character.profile.name }} niv. {{ character.level }}
+ {{ character.get_gender_display }}, {{ character.age }} ans, {{ character.height_m }}m, {{ character.weight }}kg
+ PV {{ character.health_remaining }}/{{ character.health_max }}, PM {{ character.mana_remaining }}/{{ character.mana_max }} +

+
+
+
diff --git a/src/character/templates/character/list.html b/src/character/templates/character/list.html new file mode 100644 index 0000000..dbf4557 --- /dev/null +++ b/src/character/templates/character/list.html @@ -0,0 +1,13 @@ +{% extends "common/base.html" %} +{% load character_extras %} + +{% block title %}Characters list{% endblock %} + +{% block content %} +

Characters

+
+ {% for character in characters %} + {% include "character/character_card.html" %} + {% endfor %} +
+{% endblock %} diff --git a/src/character/urls.py b/src/character/urls.py index ea150bd..b67637a 100644 --- a/src/character/urls.py +++ b/src/character/urls.py @@ -4,6 +4,7 @@ from character import views app_name = "character" urlpatterns = [ + path("", views.characters_list, name="list"), path("/", views.character_view, name="view"), path("/health_change", views.character_health_change, name="health_change"), path("/mana_change", views.character_mana_change, name="mana_change"), diff --git a/src/character/views.py b/src/character/views.py index fba7fae..845b62e 100644 --- a/src/character/views.py +++ b/src/character/views.py @@ -1,5 +1,4 @@ from django.contrib.auth.decorators import login_required -from django.core.handlers.wsgi import WSGIRequest from django.http import HttpResponse from django.shortcuts import get_object_or_404, render from django_htmx.http import trigger_client_event @@ -9,7 +8,13 @@ from character.models import Character @login_required -def character_view(request: WSGIRequest, pk: int) -> HttpResponse: +def characters_list(request): + context = {"characters": Character.objects.filter(player=request.user)} + return render(request, "character/list.html", context) + + +@login_required +def character_view(request, pk: int): character = get_object_or_404( Character.objects.select_related( "player", "racial_capability", "profile", "race" @@ -21,7 +26,7 @@ def character_view(request: WSGIRequest, pk: int) -> HttpResponse: @login_required -def character_health_change(request: WSGIRequest, pk: int) -> HttpResponse: +def character_health_change(request, pk: int): character = get_object_or_404( Character.objects.only("health_max", "health_remaining"), pk=pk ) @@ -32,7 +37,7 @@ def character_health_change(request: WSGIRequest, pk: int) -> HttpResponse: @login_required -def character_mana_change(request: WSGIRequest, pk: int) -> HttpResponse: +def character_mana_change(request, pk: int): character = get_object_or_404( Character.objects.only( "mana_remaining", "level", "value_intelligence", "profile" @@ -46,7 +51,7 @@ def character_mana_change(request: WSGIRequest, pk: int) -> HttpResponse: @login_required -def character_recovery_points_change(request: WSGIRequest, pk: int) -> HttpResponse: +def character_recovery_points_change(request, pk: int): character = get_object_or_404( Character.objects.only("recovery_points_remaining"), pk=pk ) @@ -59,7 +64,7 @@ def character_recovery_points_change(request: WSGIRequest, pk: int) -> HttpRespo @login_required -def character_defense_misc_change(request: WSGIRequest, pk: int) -> HttpResponse: +def character_defense_misc_change(request, pk: int): character = get_object_or_404(Character.objects.only("defense_misc"), pk=pk) value = get_updated_value(request, character.defense_misc, float("inf")) character.defense_misc = value @@ -69,7 +74,7 @@ def character_defense_misc_change(request: WSGIRequest, pk: int) -> HttpResponse @login_required -def character_luck_points_change(request: WSGIRequest, pk: int) -> HttpResponse: +def character_luck_points_change(request, pk: int): character = get_object_or_404( Character.objects.only("luck_points_remaining", "value_charisma"), pk=pk ) @@ -81,9 +86,7 @@ def character_luck_points_change(request: WSGIRequest, pk: int) -> HttpResponse: return HttpResponse(value) -def get_updated_value( - request: WSGIRequest, remaining_value: int, max_value: int | float -) -> int: +def get_updated_value(request, remaining_value: int, max_value: int | float) -> int: form_value = request.GET.get("value") if form_value == "ko": remaining_value = 0 @@ -98,7 +101,7 @@ def get_updated_value( @login_required -def character_get_defense(request: WSGIRequest, pk: int) -> HttpResponse: +def character_get_defense(request, pk: int): character = get_object_or_404( Character.objects.only("defense_misc", "armor", "shield", "value_dexterity"), pk=pk, @@ -107,12 +110,12 @@ def character_get_defense(request: WSGIRequest, pk: int) -> HttpResponse: @login_required -def character_notes_change(request: WSGIRequest, pk: int) -> HttpResponse: +def character_notes_change(request, pk: int): return update_text_field(request, pk, "notes") @login_required -def character_equipment_change(request: WSGIRequest, pk: int) -> HttpResponse: +def character_equipment_change(request, pk: int): field = "equipment" character = get_object_or_404(Character.objects.only(field), pk=pk) context = {"character": character} @@ -128,7 +131,7 @@ def character_equipment_change(request: WSGIRequest, pk: int) -> HttpResponse: @login_required -def character_damage_reduction_change(request: WSGIRequest, pk: int) -> HttpResponse: +def character_damage_reduction_change(request, pk: int): return update_text_field(request, pk, "damage_reduction") diff --git a/src/common/views.py b/src/common/views.py index 4dd684e..8009758 100644 --- a/src/common/views.py +++ b/src/common/views.py @@ -1,12 +1,7 @@ -import random - from django.core.handlers.wsgi import WSGIRequest from django.http import HttpResponse -from django.shortcuts import render +from django.shortcuts import redirect def hello_world(request: WSGIRequest) -> HttpResponse: - context = {"value": random.randint(1, 1000)} # noqa: S311 - if request.htmx: - return render(request, "common/hello-random.html", context) - return render(request, "common/base.html", context) + return redirect("character:list")