mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-12-22 13:51:49 +01:00
Import racial capabilities
This commit is contained in:
parent
9471b8c70b
commit
702b5f036e
4 changed files with 61 additions and 5 deletions
|
@ -2,7 +2,7 @@ from django.core.management import BaseCommand
|
|||
from selenium import webdriver
|
||||
from selenium.webdriver.common.by import By
|
||||
|
||||
from character.models import Race
|
||||
from character.models import Race, RacialCapability
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
@ -26,6 +26,25 @@ class Command(BaseCommand):
|
|||
race, _ = Race.objects.update_or_create(name=name, defaults={"url": url})
|
||||
self.stdout.write(self.style.SUCCESS(f"Created/updated race {race}"))
|
||||
|
||||
racial_cap = self.selenium.find_element(
|
||||
By.CSS_SELECTOR, ".field--name-abilities"
|
||||
)
|
||||
racial_name = (
|
||||
racial_cap.find_element(By.TAG_NAME, "strong")
|
||||
.text.strip()
|
||||
.removesuffix(":")
|
||||
.strip()
|
||||
)
|
||||
description = (
|
||||
racial_cap.text.replace(racial_name, "").strip().removeprefix(":").strip()
|
||||
)
|
||||
racial, _ = RacialCapability.objects.update_or_create(
|
||||
name=racial_name,
|
||||
race=race,
|
||||
defaults={"description": description, "url": url},
|
||||
)
|
||||
self.stdout.write(self.style.SUCCESS(f"Created/updated racial cap {racial}"))
|
||||
|
||||
def fix_name(self, name: str) -> str:
|
||||
if name == "Elfe, haut":
|
||||
return "Haut-Elfe"
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
# Generated by Django 4.1.2 on 2022-10-30 08:59
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("character", "0010_racialcapability_url"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="racialcapability",
|
||||
name="name",
|
||||
field=models.CharField(max_length=100),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="racialcapability",
|
||||
constraint=models.UniqueConstraint(
|
||||
models.F("name"), models.F("race"), name="unique_name_race"
|
||||
),
|
||||
),
|
||||
]
|
|
@ -1 +1 @@
|
|||
0010_racialcapability_url
|
||||
0011_alter_racialcapability_name_and_more
|
||||
|
|
|
@ -45,11 +45,24 @@ class Capability(DocumentedModel, UniquelyNamedModel, TimeStampedModel, models.M
|
|||
verbose_name_plural = "Capabilities"
|
||||
|
||||
|
||||
class RacialCapability(
|
||||
DocumentedModel, UniquelyNamedModel, TimeStampedModel, models.Model
|
||||
):
|
||||
class RacialCapabilityManager(models.Manager):
|
||||
def get_by_natural_key(self, name: str, race_id: int):
|
||||
return self.get(name=name, race_id=race_id)
|
||||
|
||||
|
||||
class RacialCapability(DocumentedModel, TimeStampedModel, models.Model):
|
||||
name = models.CharField(max_length=100, blank=False, null=False)
|
||||
race = models.ForeignKey("character.Race", on_delete=models.CASCADE)
|
||||
description = models.TextField()
|
||||
|
||||
objects = RacialCapabilityManager()
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "Racial capabilities"
|
||||
constraints = [models.UniqueConstraint("name", "race", name="unique_name_race")]
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name} ({self.race})"
|
||||
|
||||
def natural_key(self):
|
||||
return (self.name, self.race_id)
|
||||
|
|
Loading…
Reference in a new issue