diff --git a/src/character/forms.py b/src/character/forms.py index 8d25a0e..e341ee8 100644 --- a/src/character/forms.py +++ b/src/character/forms.py @@ -24,8 +24,10 @@ class AddPathForm(forms.Form): def __init__(self, character: Character, *args, **kwargs): super().__init__(*args, **kwargs) paths = {cap.path_id for cap in character.capabilities.all()} - paths = Path.objects.exclude(pk__in=paths).order_by( - "profile__name", "race__name" + paths = ( + Path.objects.exclude(pk__in=paths) + .order_by("profile__name", "race__name") + .select_related("profile", "race") ) character_paths = paths.filter( Q(profile=character.profile) | Q(race=character.race) diff --git a/src/character/migrations/0031_alter_harmfulstate_options.py b/src/character/migrations/0031_alter_harmfulstate_options.py new file mode 100644 index 0000000..a251c9b --- /dev/null +++ b/src/character/migrations/0031_alter_harmfulstate_options.py @@ -0,0 +1,21 @@ +# Generated by Django 4.1.2 on 2022-11-02 21:01 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("character", "0030_alter_character_states"), + ] + + operations = [ + migrations.AlterModelOptions( + name="harmfulstate", + options={ + "ordering": ["name"], + "verbose_name": "État préjudiciable", + "verbose_name_plural": "États préjudiciables", + }, + ), + ] diff --git a/src/character/migrations/max_migration.txt b/src/character/migrations/max_migration.txt index 8f8b1da..626f3dd 100644 --- a/src/character/migrations/max_migration.txt +++ b/src/character/migrations/max_migration.txt @@ -1 +1 @@ -0030_alter_character_states +0031_alter_harmfulstate_options diff --git a/src/character/models/character.py b/src/character/models/character.py index 1dd20c4..7bf11c9 100644 --- a/src/character/models/character.py +++ b/src/character/models/character.py @@ -1,4 +1,5 @@ import collections +from collections.abc import Iterable import markdown from django.db import models @@ -56,6 +57,7 @@ class HarmfulState(DocumentedModel, UniquelyNamedModel, TimeStampedModel, models class Meta: verbose_name = "État préjudiciable" verbose_name_plural = "États préjudiciables" + ordering = ["name"] def modifier(value: int) -> int: @@ -318,3 +320,8 @@ class Character(models.Model): def get_formatted_notes(self) -> str: md = markdown.Markdown(extensions=["extra", "nl2br"]) return md.convert(self.notes) + + def get_missing_states(self) -> Iterable[HarmfulState]: + return HarmfulState.objects.exclude( + pk__in=self.states.all().values_list("pk", flat=True) + ) diff --git a/src/character/static/character/style.css b/src/character/static/character/style.css new file mode 100644 index 0000000..88d9572 --- /dev/null +++ b/src/character/static/character/style.css @@ -0,0 +1,3 @@ +.state-enabled { + filter: invert(50%) sepia(100%) saturate(3000%) hue-rotate(325deg); +} diff --git a/src/character/templates/character/states.html b/src/character/templates/character/states.html index 0fdcf58..6137566 100644 --- a/src/character/templates/character/states.html +++ b/src/character/templates/character/states.html @@ -1,15 +1,20 @@

États : - {% for state in character.states.all %} - {{ state.name }} - {% empty %} - Aucun - {% endfor %} + {% with character.states.all as character_states %} + {% for state in all_states %} + {{ state.name }} + {% endfor %} + {% endwith %}

diff --git a/src/character/templates/character/view.html b/src/character/templates/character/view.html index 246c7ee..e6c6dc8 100644 --- a/src/character/templates/character/view.html +++ b/src/character/templates/character/view.html @@ -1,9 +1,14 @@ {% extends "common/base.html" %} +{% load static %} {% load django_bootstrap5 %} {% load character_extras %} {% block title %}{{ character.name }}{% endblock %} +{% block head_end %} + +{% endblock %} + {% block content %}

{{ character.name }}

diff --git a/src/character/urls.py b/src/character/urls.py index a333358..05a80c6 100644 --- a/src/character/urls.py +++ b/src/character/urls.py @@ -72,4 +72,5 @@ urlpatterns = [ path( "/remove_state//", views.remove_state, name="remove_state" ), + path("/add_state//", views.add_state, name="add_state"), ] diff --git a/src/character/views.py b/src/character/views.py index 0d5ba34..243f2ee 100644 --- a/src/character/views.py +++ b/src/character/views.py @@ -32,7 +32,11 @@ def character_view(request, pk: int): pk=pk, ) add_path_form = AddPathForm(character) - context = {"character": character, "add_path_form": add_path_form} + context = { + "character": character, + "add_path_form": add_path_form, + "all_states": HarmfulState.objects.all(), + } return render(request, "character/view.html", context) @@ -274,6 +278,18 @@ 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} + context = {"character": character, "all_states": HarmfulState.objects.all()} + response = render(request, "character/states.html", context) + return trigger_client_event(response, "refresh_tooltips", {}) + + +@login_required +def add_state(request, pk: int, state_pk: int): + character: Character = get_object_or_404( + Character.objects.filter(player=request.user), pk=pk + ) + 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) return trigger_client_event(response, "refresh_tooltips", {}) diff --git a/src/common/templates/common/base.html b/src/common/templates/common/base.html index 2b5e04b..372ef6c 100644 --- a/src/common/templates/common/base.html +++ b/src/common/templates/common/base.html @@ -16,6 +16,8 @@ touch-action: manipulation; } + {% block head_end %} + {% endblock %} {% include "common/navbar.html" %}