mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-11-05 14:23:53 +01:00
feat: add a path without capabilities (closes #28)
This commit is contained in:
parent
4124b65c7a
commit
c667ed54c6
6 changed files with 53 additions and 15 deletions
|
@ -171,7 +171,7 @@ class CharacterAdmin(admin.ModelAdmin):
|
|||
},
|
||||
),
|
||||
("Race", {"fields": ["racial_capability"]}),
|
||||
("Capacités", {"fields": ["capabilities"]}),
|
||||
("Voies & capacités", {"fields": ["paths", "capabilities"]}),
|
||||
("Chance", {"fields": [("luck_points_max", "luck_points_remaining")]}),
|
||||
("Mana", {"fields": [("mana_max", "mana_remaining")]}),
|
||||
(
|
||||
|
|
21
src/character/migrations/0043_character_paths.py
Normal file
21
src/character/migrations/0043_character_paths.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Generated by Django 4.2.2 on 2023-06-19 15:34
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("character", "0042_alter_pet_damage"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="character",
|
||||
name="paths",
|
||||
field=models.ManyToManyField(
|
||||
blank=True,
|
||||
to="character.path",
|
||||
verbose_name="voies",
|
||||
),
|
||||
),
|
||||
]
|
|
@ -1 +1 @@
|
|||
0042_alter_pet_damage
|
||||
0043_character_paths
|
||||
|
|
|
@ -254,6 +254,7 @@ class Character(models.Model):
|
|||
blank=True,
|
||||
verbose_name="capacités",
|
||||
)
|
||||
paths = models.ManyToManyField("character.Path", blank=True, verbose_name="voies")
|
||||
|
||||
equipment = models.TextField(blank=True, verbose_name="équipement")
|
||||
luck_points_remaining = models.PositiveSmallIntegerField(
|
||||
|
@ -428,8 +429,10 @@ class Character(models.Model):
|
|||
|
||||
def get_capabilities_by_path(self) -> dict[Path, list[CharacterCapability]]:
|
||||
capabilities_by_path = collections.defaultdict(list)
|
||||
character_capabilities = self.capabilities.all()
|
||||
character_paths = {capability.path for capability in character_capabilities}
|
||||
character_capabilities = set(self.capabilities.all())
|
||||
character_paths = {
|
||||
capability.path for capability in character_capabilities
|
||||
} | set(self.paths.all())
|
||||
for path in character_paths:
|
||||
for capability in path.capabilities.all():
|
||||
capabilities_by_path[capability.path].append(
|
||||
|
|
|
@ -103,8 +103,7 @@ def add_path(request, pk: int):
|
|||
path: Path = form.cleaned_data.get("character_path") or form.cleaned_data.get(
|
||||
"other_path",
|
||||
)
|
||||
cap = path.get_next_capability(character)
|
||||
character.capabilities.add(cap)
|
||||
character.paths.add(path)
|
||||
context["add_path_form"] = AddPathForm(character)
|
||||
else:
|
||||
context["add_path_form"] = form
|
||||
|
@ -400,11 +399,21 @@ def remove_last_in_path(request, character_pk: int, path_pk: int):
|
|||
Character.objects.managed_by(request.user),
|
||||
pk=character_pk,
|
||||
)
|
||||
last_rank = max(
|
||||
character.capabilities.filter(path_id=path_pk).values_list("rank", flat=True),
|
||||
capabilities = character.capabilities.filter(path_id=path_pk).values_list(
|
||||
"rank",
|
||||
flat=True,
|
||||
)
|
||||
cap = Capability.objects.get(path_id=path_pk, rank=last_rank)
|
||||
character.capabilities.remove(cap)
|
||||
if len(capabilities) == 0:
|
||||
character.paths.remove(path_pk)
|
||||
else:
|
||||
last_rank = max(
|
||||
character.capabilities.filter(path_id=path_pk).values_list(
|
||||
"rank",
|
||||
flat=True,
|
||||
),
|
||||
)
|
||||
cap = Capability.objects.get(path_id=path_pk, rank=last_rank)
|
||||
character.capabilities.remove(cap)
|
||||
context = {
|
||||
"character": character,
|
||||
"add_path_form": AddPathForm(character),
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
|
@ -41,12 +42,16 @@ INTERNAL_IPS = [
|
|||
ALLOWED_HOSTS = env("ALLOWED_HOSTS")
|
||||
|
||||
if DEBUG:
|
||||
import socket
|
||||
try:
|
||||
import socket
|
||||
|
||||
hostname = socket.gethostname()
|
||||
ip = socket.gethostbyname(hostname)
|
||||
INTERNAL_IPS.append(ip)
|
||||
ALLOWED_HOSTS.append(ip)
|
||||
except Exception as e:
|
||||
logging.info("couldn't setup allowed host in debug: %s", e)
|
||||
|
||||
hostname = socket.gethostname()
|
||||
ip = socket.gethostbyname(hostname)
|
||||
INTERNAL_IPS.append(ip)
|
||||
ALLOWED_HOSTS.append(ip)
|
||||
|
||||
CSRF_TRUSTED_ORIGINS = env("CSRF_TRUSTED_ORIGINS")
|
||||
|
||||
|
|
Loading…
Reference in a new issue