From 9471b8c70b730da0a4d9b89142a6d406168b51c6 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sun, 30 Oct 2022 09:44:28 +0100 Subject: [PATCH] Add link to CO website --- src/character/admin.py | 13 +++++++ .../commands/import_capabilities.py | 1 + .../management/commands/import_paths.py | 1 + .../management/commands/import_profiles.py | 1 + .../management/commands/import_races.py | 2 +- ..._path_url_profile_url_race_url_and_more.py | 38 +++++++++++++++++++ .../0009_remove_racialcapability_url.py | 17 +++++++++ .../migrations/0010_racialcapability_url.py | 18 +++++++++ src/character/migrations/max_migration.txt | 2 +- src/character/models/capabilities.py | 10 +++-- src/character/models/character.py | 6 +-- src/common/models.py | 7 ++++ 12 files changed, 107 insertions(+), 9 deletions(-) create mode 100644 src/character/migrations/0008_capability_url_path_url_profile_url_race_url_and_more.py create mode 100644 src/character/migrations/0009_remove_racialcapability_url.py create mode 100644 src/character/migrations/0010_racialcapability_url.py diff --git a/src/character/admin.py b/src/character/admin.py index dd293c1..9596b08 100644 --- a/src/character/admin.py +++ b/src/character/admin.py @@ -8,6 +8,13 @@ class CapabilityAdmin(admin.ModelAdmin): list_display = ["name", "path", "rank", "limited", "spell"] list_filter = ["path", "path__profile", "path__race", "rank", "limited", "spell"] search_fields = ["name", "description"] + fieldsets = [ + (None, {"fields": ["name"]}), + ("Path", {"fields": [("path", "rank")]}), + ("Type", {"fields": [("limited", "spell")]}), + ("Description", {"fields": ["description"]}), + ("Documentation", {"fields": ["url"]}), + ] @admin.register(models.Path) @@ -19,6 +26,7 @@ class PathAdmin(admin.ModelAdmin): (None, {"fields": ["name"]}), ("Related to", {"fields": ["category", ("profile", "race")]}), ("Notes", {"fields": ["notes"]}), + ("Documentation", {"fields": ["url"]}), ] def related_to(self, instance: models.Path) -> str: @@ -50,6 +58,11 @@ class ProfileAdmin(admin.ModelAdmin): list_filter = ["life_dice", "magical_strength"] search_fields = ["name"] inlines = [PathInline] + fieldsets = [ + (None, {"fields": ["name", ("magical_strength", "life_dice")]}), + ("Notes", {"fields": ["notes"]}), + ("Documentation", {"fields": ["url"]}), + ] class RacialCapabilityInline(admin.TabularInline): diff --git a/src/character/management/commands/import_capabilities.py b/src/character/management/commands/import_capabilities.py index 788a837..72f2b94 100644 --- a/src/character/management/commands/import_capabilities.py +++ b/src/character/management/commands/import_capabilities.py @@ -52,6 +52,7 @@ class Command(BaseCommand): "path": path, "limited": limited, "spell": spell, + "url": "https://www.co-drs.org/fr/jeu/capacites", }, ) self.stdout.write(self.style.SUCCESS(f"Created/updated cap {capability}")) diff --git a/src/character/management/commands/import_paths.py b/src/character/management/commands/import_paths.py index a7c0588..751cd25 100644 --- a/src/character/management/commands/import_paths.py +++ b/src/character/management/commands/import_paths.py @@ -48,6 +48,7 @@ class Command(BaseCommand): "profile": profile, "race": race, "notes": notes, + "url": url, }, ) self.stdout.write(self.style.SUCCESS(f"Created/updated path {path}")) diff --git a/src/character/management/commands/import_profiles.py b/src/character/management/commands/import_profiles.py index 6b897e8..787e63e 100644 --- a/src/character/management/commands/import_profiles.py +++ b/src/character/management/commands/import_profiles.py @@ -32,6 +32,7 @@ class Command(BaseCommand): "life_dice": dice, "magical_strength": magical_strength, "notes": notes, + "url": url, }, ) self.stdout.write(self.style.SUCCESS(f"Created/updated profile {profile}")) diff --git a/src/character/management/commands/import_races.py b/src/character/management/commands/import_races.py index 686354f..c51343f 100644 --- a/src/character/management/commands/import_races.py +++ b/src/character/management/commands/import_races.py @@ -23,7 +23,7 @@ class Command(BaseCommand): self.selenium.get(url) name = self.selenium.find_element(By.TAG_NAME, "h1").text.strip() name = self.fix_name(name) - race, _ = Race.objects.update_or_create(name=name, defaults={}) + race, _ = Race.objects.update_or_create(name=name, defaults={"url": url}) self.stdout.write(self.style.SUCCESS(f"Created/updated race {race}")) def fix_name(self, name: str) -> str: diff --git a/src/character/migrations/0008_capability_url_path_url_profile_url_race_url_and_more.py b/src/character/migrations/0008_capability_url_path_url_profile_url_race_url_and_more.py new file mode 100644 index 0000000..7edbd58 --- /dev/null +++ b/src/character/migrations/0008_capability_url_path_url_profile_url_race_url_and_more.py @@ -0,0 +1,38 @@ +# Generated by Django 4.1.2 on 2022-10-30 08:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("character", "0007_alter_capability_limited_alter_capability_spell"), + ] + + operations = [ + migrations.AddField( + model_name="capability", + name="url", + field=models.URLField(blank=True), + ), + migrations.AddField( + model_name="path", + name="url", + field=models.URLField(blank=True), + ), + migrations.AddField( + model_name="profile", + name="url", + field=models.URLField(blank=True), + ), + migrations.AddField( + model_name="race", + name="url", + field=models.URLField(blank=True), + ), + migrations.AddField( + model_name="racialcapability", + name="url", + field=models.URLField(blank=True), + ), + ] diff --git a/src/character/migrations/0009_remove_racialcapability_url.py b/src/character/migrations/0009_remove_racialcapability_url.py new file mode 100644 index 0000000..27be90c --- /dev/null +++ b/src/character/migrations/0009_remove_racialcapability_url.py @@ -0,0 +1,17 @@ +# Generated by Django 4.1.2 on 2022-10-30 08:43 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("character", "0008_capability_url_path_url_profile_url_race_url_and_more"), + ] + + operations = [ + migrations.RemoveField( + model_name="racialcapability", + name="url", + ), + ] diff --git a/src/character/migrations/0010_racialcapability_url.py b/src/character/migrations/0010_racialcapability_url.py new file mode 100644 index 0000000..9312df2 --- /dev/null +++ b/src/character/migrations/0010_racialcapability_url.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.2 on 2022-10-30 08:44 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("character", "0009_remove_racialcapability_url"), + ] + + operations = [ + migrations.AddField( + model_name="racialcapability", + name="url", + field=models.URLField(blank=True), + ), + ] diff --git a/src/character/migrations/max_migration.txt b/src/character/migrations/max_migration.txt index 5cdfc74..3350a6b 100644 --- a/src/character/migrations/max_migration.txt +++ b/src/character/migrations/max_migration.txt @@ -1 +1 @@ -0007_alter_capability_limited_alter_capability_spell +0010_racialcapability_url diff --git a/src/character/models/capabilities.py b/src/character/models/capabilities.py index ffccd67..79b640a 100644 --- a/src/character/models/capabilities.py +++ b/src/character/models/capabilities.py @@ -2,10 +2,10 @@ from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models from django_extensions.db.models import TimeStampedModel -from common.models import UniquelyNamedModel +from common.models import DocumentedModel, UniquelyNamedModel -class Path(UniquelyNamedModel, TimeStampedModel, models.Model): +class Path(DocumentedModel, UniquelyNamedModel, TimeStampedModel, models.Model): profile = models.ForeignKey( "character.Profile", on_delete=models.CASCADE, @@ -31,7 +31,7 @@ class Path(UniquelyNamedModel, TimeStampedModel, models.Model): notes = models.TextField(blank=True) -class Capability(UniquelyNamedModel, TimeStampedModel, models.Model): +class Capability(DocumentedModel, UniquelyNamedModel, TimeStampedModel, models.Model): path = models.ForeignKey("character.Path", on_delete=models.CASCADE) rank = models.PositiveSmallIntegerField( validators=[MinValueValidator(1), MaxValueValidator(5)] @@ -45,7 +45,9 @@ class Capability(UniquelyNamedModel, TimeStampedModel, models.Model): verbose_name_plural = "Capabilities" -class RacialCapability(UniquelyNamedModel, TimeStampedModel, models.Model): +class RacialCapability( + DocumentedModel, UniquelyNamedModel, TimeStampedModel, models.Model +): race = models.ForeignKey("character.Race", on_delete=models.CASCADE) description = models.TextField() diff --git a/src/character/models/character.py b/src/character/models/character.py index c0f3290..7c66855 100644 --- a/src/character/models/character.py +++ b/src/character/models/character.py @@ -3,10 +3,10 @@ from django.db.models.functions import Lower from django_extensions.db.models import TimeStampedModel from character.models.dice import Dice -from common.models import UniquelyNamedModel +from common.models import DocumentedModel, UniquelyNamedModel -class Profile(UniquelyNamedModel, TimeStampedModel, models.Model): +class Profile(DocumentedModel, UniquelyNamedModel, TimeStampedModel, models.Model): class MagicalStrength(models.TextChoices): NONE = "NON", "None" INTELLIGENCE = "INT", "Intelligence" @@ -20,7 +20,7 @@ class Profile(UniquelyNamedModel, TimeStampedModel, models.Model): notes = models.TextField(blank=True) -class Race(UniquelyNamedModel, TimeStampedModel, models.Model): +class Race(DocumentedModel, UniquelyNamedModel, TimeStampedModel, models.Model): pass diff --git a/src/common/models.py b/src/common/models.py index ef9ecf4..135c2e2 100644 --- a/src/common/models.py +++ b/src/common/models.py @@ -25,3 +25,10 @@ class UniquelyNamedModel(models.Model): def natural_key(self): return (self.name,) + + +class DocumentedModel(models.Model): + url = models.URLField(blank=True, null=False) + + class Meta: + abstract = True