Improve notes display & fix character creation defaults

This commit is contained in:
Gabriel Augendre 2022-10-31 00:42:26 +01:00
parent b12ea84db4
commit d80172e96a
11 changed files with 149 additions and 14 deletions

17
poetry.lock generated
View file

@ -399,6 +399,17 @@ python-versions = "*"
[package.dependencies]
ansicon = {version = "*", markers = "platform_system == \"Windows\""}
[[package]]
name = "markdown"
version = "3.4.1"
description = "Python implementation of Markdown."
category = "main"
optional = false
python-versions = ">=3.7"
[package.extras]
testing = ["coverage", "pyyaml"]
[[package]]
name = "model-bakery"
version = "1.9.0"
@ -905,7 +916,7 @@ h11 = ">=0.9.0,<1"
[metadata]
lock-version = "1.1"
python-versions = ">=3.10.0, <4"
content-hash = "96bceed911ff3dca55ddfc85bf7d48e9056111b55aad6e05da5d3ebd2e9a60aa"
content-hash = "df8aa35ecf2515691ed8ffdccbfb63f503c9330db3cd806d7dc8a8689f64328e"
[metadata.files]
ansicon = [
@ -1255,6 +1266,10 @@ jinxed = [
{file = "jinxed-1.2.0-py2.py3-none-any.whl", hash = "sha256:cfc2b2e4e3b4326954d546ba6d6b9a7a796ddcb0aef8d03161d005177eb0d48b"},
{file = "jinxed-1.2.0.tar.gz", hash = "sha256:032acda92d5c57cd216033cbbd53de731e6ed50deb63eb4781336ca55f72cda5"},
]
markdown = [
{file = "Markdown-3.4.1-py3-none-any.whl", hash = "sha256:08fb8465cffd03d10b9dd34a5c3fea908e20391a2a90b88d66362cb05beed186"},
{file = "Markdown-3.4.1.tar.gz", hash = "sha256:3b809086bb6efad416156e00a0da66fe47618a5d6918dd688f53f40c8e4cfeff"},
]
model-bakery = [
{file = "model_bakery-1.9.0-py2.py3-none-any.whl", hash = "sha256:93ac818df49377d4f14316105028fa95231474bf268d6017e420e5d4b74d54fd"},
{file = "model_bakery-1.9.0.tar.gz", hash = "sha256:99571801a26b85b8dcba7f0ad39750aeb2f2477fe770d2291823e16788785000"},

View file

@ -19,6 +19,7 @@ psycopg2-binary = ">=2.8"
whitenoise = ">=6.2"
uWSGI = ">=2.0.21"
selenium = ">=4.5.0"
Markdown = ">=3.2"
[tool.poetry.dev-dependencies]
django-debug-toolbar = ">=3.2"

View file

@ -0,0 +1,22 @@
# Generated by Django 4.1.2 on 2022-10-30 23:39
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("character", "0020_alter_weapon_category"),
]
operations = [
migrations.AlterField(
model_name="character",
name="notes",
field=models.TextField(
blank=True,
default="### Traits personnalisés\n\n### Objectifs\n\n### Langages\n\n### Historique\n\n### Handicaps\n\n### Alignement\n\n### Relations\n\n### Religion\n",
verbose_name="notes",
),
),
]

View file

@ -0,0 +1,18 @@
# Generated by Django 4.1.2 on 2022-10-30 23:40
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("character", "0021_alter_character_notes"),
]
operations = [
migrations.AlterField(
model_name="character",
name="level",
field=models.PositiveSmallIntegerField(default=1, verbose_name="niveau"),
),
]

View file

@ -0,0 +1,28 @@
# Generated by Django 4.1.2 on 2022-10-30 23:40
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("character", "0022_alter_character_level"),
]
operations = [
migrations.AlterField(
model_name="character",
name="armor",
field=models.PositiveSmallIntegerField(default=0, verbose_name="armure"),
),
migrations.AlterField(
model_name="character",
name="defense_misc",
field=models.SmallIntegerField(default=0, verbose_name="divers défense"),
),
migrations.AlterField(
model_name="character",
name="shield",
field=models.PositiveSmallIntegerField(default=0, verbose_name="bouclier"),
),
]

View file

@ -0,0 +1,25 @@
# Generated by Django 4.1.2 on 2022-10-30 23:42
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
(
"character",
"0023_alter_character_armor_alter_character_defense_misc_and_more",
),
]
operations = [
migrations.AlterField(
model_name="character",
name="notes",
field=models.TextField(
blank=True,
default="#### Traits personnalisés\n\n#### Objectifs\n\n#### Langages\n\n#### Historique\n\n#### Handicaps\n\n#### Alignement\n\n#### Relations\n\n#### Religion\n",
verbose_name="notes",
),
),
]

View file

@ -1 +1 @@
0020_alter_weapon_category
0024_alter_character_notes

View file

@ -1,5 +1,6 @@
import collections
import markdown
from django.db import models
from django.db.models.functions import Lower
from django.urls import reverse
@ -49,6 +50,8 @@ class Race(DocumentedModel, UniquelyNamedModel, TimeStampedModel, models.Model):
def modifier(value: int) -> int:
if not value:
return 0
if 1 < value < 10:
value -= 1
value -= 10
@ -60,6 +63,25 @@ class CharacterManager(models.Manager):
return self.get(name=name, player_id=player_id)
DEFAULT_NOTES = """
#### Traits personnalisés
#### Objectifs
#### Langages
#### Historique
#### Handicaps
#### Alignement
#### Relations
#### Religion
""".lstrip()
class Character(models.Model):
class Gender(models.TextChoices):
MALE = "M", "Mâle"
@ -86,7 +108,7 @@ class Character(models.Model):
related_name="characters",
verbose_name="profil",
)
level = models.PositiveSmallIntegerField(verbose_name="niveau")
level = models.PositiveSmallIntegerField(verbose_name="niveau", default=1)
gender = models.CharField(
max_length=1, choices=Gender.choices, default=Gender.OTHER, verbose_name="genre"
@ -122,9 +144,9 @@ class Character(models.Model):
"character.Weapon", blank=True, verbose_name="armes"
)
armor = models.PositiveSmallIntegerField(verbose_name="armure")
shield = models.PositiveSmallIntegerField(verbose_name="bouclier")
defense_misc = models.SmallIntegerField(verbose_name="divers défense")
armor = models.PositiveSmallIntegerField(verbose_name="armure", default=0)
shield = models.PositiveSmallIntegerField(verbose_name="bouclier", default=0)
defense_misc = models.SmallIntegerField(verbose_name="divers défense", default=0)
capabilities = models.ManyToManyField(
"character.Capability", blank=True, verbose_name="capacités"
@ -148,7 +170,7 @@ class Character(models.Model):
default=5, verbose_name="points de récupération restants"
)
notes = models.TextField(blank=True, verbose_name="notes")
notes = models.TextField(blank=True, verbose_name="notes", default=DEFAULT_NOTES)
damage_reduction = models.TextField(blank=True, verbose_name="réduction de dégâts")
objects = CharacterManager()
@ -277,3 +299,7 @@ class Character(models.Model):
key=lambda x: x[0].name,
)
)
def get_formatted_notes(self) -> str:
md = markdown.Markdown(extensions=["extra", "nl2br"])
return md.convert(self.notes)

View file

@ -1,5 +1,5 @@
<div class="row" id="notes">
<h4 class="mt-3">
<div class="mt-3" id="notes">
<h2>
Notes
<a hx-get="{% url "character:notes_change" pk=character.pk %}"
hx-target="#notes"
@ -8,6 +8,6 @@
>
<i class="fa-solid fa-pen-to-square"></i> Edit
</a>
</h4>
{{ character.notes|linebreaks }}
</h2>
{{ character.get_formatted_notes|safe }}
</div>

View file

@ -1,6 +1,6 @@
<div class="row" id="notes">
<div class="mt-3" id="notes">
<form>
<h4 class="mt-3">
<h4>
Notes
<a hx-post="{% url "character:notes_change" pk=character.pk %}"
hx-target="#notes"

View file

@ -335,7 +335,7 @@
{% include "character/equipment_display.html" %}
</div>
</div>
<h4>Voies & Capacités</h4>
<h2>Voies & Capacités</h2>
<div class="row gy-3">
{% for path, capabilities in character.get_capabilities_by_path.items %}
<div class="col-xl-3 col-md-6">