mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-11-22 14:38:03 +01:00
Fix capabilities import
This commit is contained in:
parent
d17a5bba70
commit
ba4c5457d0
5 changed files with 1616 additions and 865 deletions
File diff suppressed because it is too large
Load diff
|
@ -34,7 +34,7 @@ class Command(BaseCommand):
|
||||||
)
|
)
|
||||||
name = title[0].replace("’", "'").strip()
|
name = title[0].replace("’", "'").strip()
|
||||||
rank = int(title[1].replace("rang ", ""))
|
rank = int(title[1].replace("rang ", ""))
|
||||||
path = self.get_path(card, name)
|
paths = self.get_paths(card, name)
|
||||||
limited = False
|
limited = False
|
||||||
if "(L)" in name:
|
if "(L)" in name:
|
||||||
limited = True
|
limited = True
|
||||||
|
@ -49,46 +49,39 @@ class Command(BaseCommand):
|
||||||
.text.strip()
|
.text.strip()
|
||||||
.replace("’", "'")
|
.replace("’", "'")
|
||||||
)
|
)
|
||||||
try:
|
for path in paths:
|
||||||
capability, _ = Capability.objects.update_or_create(
|
try:
|
||||||
name=name,
|
capability, _ = Capability.objects.update_or_create(
|
||||||
defaults={
|
rank=rank,
|
||||||
"rank": rank,
|
path=path,
|
||||||
"path": path,
|
defaults={
|
||||||
"limited": limited,
|
"name": name,
|
||||||
"spell": spell,
|
"limited": limited,
|
||||||
"description": description,
|
"spell": spell,
|
||||||
"url": "https://www.co-drs.org/fr/jeu/capacites",
|
"description": description,
|
||||||
},
|
"url": "https://www.co-drs.org/fr/jeu/capacites",
|
||||||
)
|
},
|
||||||
self.stdout.write(self.style.SUCCESS(f"Created/updated cap {capability}"))
|
)
|
||||||
except Exception as e:
|
self.stdout.write(
|
||||||
self.stdout.write(
|
self.style.SUCCESS(f"Created/updated cap {capability}")
|
||||||
self.style.ERROR(f"Couldn't create/update cap {name}: {e}")
|
)
|
||||||
)
|
except Exception as e:
|
||||||
|
self.stdout.write(
|
||||||
|
self.style.ERROR(f"Couldn't create/update cap {name}: {e}")
|
||||||
|
)
|
||||||
|
|
||||||
def get_path(self, card: WebElement, name: str) -> Path | None:
|
def get_paths(self, card: WebElement, name: str) -> list[Path]:
|
||||||
|
paths = []
|
||||||
try:
|
try:
|
||||||
path_name = (
|
for elem in card.find_elements(By.CSS_SELECTOR, ".card-back .paths a"):
|
||||||
card.find_element(By.CSS_SELECTOR, ".card-back .paths a")
|
path_name = elem.text.replace("’", "'").strip()
|
||||||
.text.replace("’", "'")
|
paths.append(Path.objects.get(name__iexact=path_name))
|
||||||
.strip()
|
|
||||||
)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
self.stdout.write(
|
self.stdout.write(
|
||||||
self.style.WARNING(f"Couldn't find path in card for cap '{name}'.")
|
self.style.WARNING(f"Couldn't find path in card for cap '{name}'.")
|
||||||
)
|
)
|
||||||
return None
|
return []
|
||||||
try:
|
return paths
|
||||||
path = Path.objects.get(name__iexact=path_name)
|
|
||||||
return path
|
|
||||||
except Exception:
|
|
||||||
self.stdout.write(
|
|
||||||
self.style.WARNING(
|
|
||||||
f"Couldn't find path name '{path_name}' for cap '{name}'."
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return None
|
|
||||||
|
|
||||||
def setup_selenium(self):
|
def setup_selenium(self):
|
||||||
options = webdriver.FirefoxOptions()
|
options = webdriver.FirefoxOptions()
|
||||||
|
|
18
src/character/migrations/0026_alter_capability_name.py
Normal file
18
src/character/migrations/0026_alter_capability_name.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 4.1.2 on 2022-11-01 08:12
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("character", "0025_alter_capability_path"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="capability",
|
||||||
|
name="name",
|
||||||
|
field=models.CharField(max_length=100, verbose_name="nom"),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1 +1 @@
|
||||||
0025_alter_capability_path
|
0026_alter_capability_name
|
||||||
|
|
|
@ -76,7 +76,13 @@ class Path(DocumentedModel, UniquelyNamedModel, TimeStampedModel, models.Model):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class Capability(DocumentedModel, UniquelyNamedModel, TimeStampedModel, models.Model):
|
class CapabilityManager(models.Manager):
|
||||||
|
def get_by_natural_key(self, path_id, rank):
|
||||||
|
return self.get(path_id=path_id, rank=rank)
|
||||||
|
|
||||||
|
|
||||||
|
class Capability(DocumentedModel, TimeStampedModel, models.Model):
|
||||||
|
name = models.CharField(max_length=100, blank=False, null=False, verbose_name="nom")
|
||||||
path = models.ForeignKey(
|
path = models.ForeignKey(
|
||||||
"character.Path",
|
"character.Path",
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
|
@ -94,6 +100,8 @@ class Capability(DocumentedModel, UniquelyNamedModel, TimeStampedModel, models.M
|
||||||
)
|
)
|
||||||
description = models.TextField(verbose_name="description")
|
description = models.TextField(verbose_name="description")
|
||||||
|
|
||||||
|
objects = CapabilityManager
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
constraints = [models.UniqueConstraint("path", "rank", name="unique_path_rank")]
|
constraints = [models.UniqueConstraint("path", "rank", name="unique_path_rank")]
|
||||||
verbose_name = "Capacité"
|
verbose_name = "Capacité"
|
||||||
|
@ -105,6 +113,9 @@ class Capability(DocumentedModel, UniquelyNamedModel, TimeStampedModel, models.M
|
||||||
description += f" ({self.path.related_to.name})"
|
description += f" ({self.path.related_to.name})"
|
||||||
return description
|
return description
|
||||||
|
|
||||||
|
def natural_key(self):
|
||||||
|
return (self.path_id, self.rank)
|
||||||
|
|
||||||
|
|
||||||
class RacialCapabilityManager(models.Manager):
|
class RacialCapabilityManager(models.Manager):
|
||||||
def get_by_natural_key(self, name: str, race_id: int):
|
def get_by_natural_key(self, name: str, race_id: int):
|
||||||
|
|
Loading…
Reference in a new issue