diff --git a/poetry.lock b/poetry.lock index d13a9ee..3ae1d58 100644 --- a/poetry.lock +++ b/poetry.lock @@ -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"}, diff --git a/pyproject.toml b/pyproject.toml index d185289..4d9bfb6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/src/character/migrations/0021_alter_character_notes.py b/src/character/migrations/0021_alter_character_notes.py new file mode 100644 index 0000000..e26270e --- /dev/null +++ b/src/character/migrations/0021_alter_character_notes.py @@ -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", + ), + ), + ] diff --git a/src/character/migrations/0022_alter_character_level.py b/src/character/migrations/0022_alter_character_level.py new file mode 100644 index 0000000..d4dee26 --- /dev/null +++ b/src/character/migrations/0022_alter_character_level.py @@ -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"), + ), + ] diff --git a/src/character/migrations/0023_alter_character_armor_alter_character_defense_misc_and_more.py b/src/character/migrations/0023_alter_character_armor_alter_character_defense_misc_and_more.py new file mode 100644 index 0000000..1c3f4c1 --- /dev/null +++ b/src/character/migrations/0023_alter_character_armor_alter_character_defense_misc_and_more.py @@ -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"), + ), + ] diff --git a/src/character/migrations/0024_alter_character_notes.py b/src/character/migrations/0024_alter_character_notes.py new file mode 100644 index 0000000..119d826 --- /dev/null +++ b/src/character/migrations/0024_alter_character_notes.py @@ -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", + ), + ), + ] diff --git a/src/character/migrations/max_migration.txt b/src/character/migrations/max_migration.txt index f5a4bb0..6a5eaa8 100644 --- a/src/character/migrations/max_migration.txt +++ b/src/character/migrations/max_migration.txt @@ -1 +1 @@ -0020_alter_weapon_category +0024_alter_character_notes diff --git a/src/character/models/character.py b/src/character/models/character.py index 0f64aa8..bd27927 100644 --- a/src/character/models/character.py +++ b/src/character/models/character.py @@ -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) diff --git a/src/character/templates/character/notes_display.html b/src/character/templates/character/notes_display.html index 69098eb..725018a 100644 --- a/src/character/templates/character/notes_display.html +++ b/src/character/templates/character/notes_display.html @@ -1,5 +1,5 @@ -
-

+
+

Notes Edit -

- {{ character.notes|linebreaks }} +

+ {{ character.get_formatted_notes|safe }}
diff --git a/src/character/templates/character/notes_update.html b/src/character/templates/character/notes_update.html index 004e256..5a9de5b 100644 --- a/src/character/templates/character/notes_update.html +++ b/src/character/templates/character/notes_update.html @@ -1,6 +1,6 @@ -
+
-

+

Notes

-

Voies & Capacités

+

Voies & Capacités

{% for path, capabilities in character.get_capabilities_by_path.items %}