Files
Hulumath-Web/backend/progression/services.py
Jacky 1f98f7152d
CI / test (push) Failing after 1m31s
v0.2 Preview: Construction Plan.
2026-08-08 21:25:27 +08:00

25 lines
773 B
Python

from django.db import transaction
from .models import Card, UserAbility, UserCard, UserPet
@transaction.atomic
def initialize_math_identity(user, identity):
UserPet.objects.get_or_create(user=user)
for dimension, _ in UserAbility.Dimension.choices:
UserAbility.objects.get_or_create(user=user, dimension=dimension)
card, _ = Card.objects.get_or_create(
slug=f"mathbti-{identity.code}",
defaults={
"name": f"{identity.mathematician}人物卡",
"mathematician": identity.mathematician,
"description": identity.description,
"image": identity.portrait,
},
)
UserCard.objects.get_or_create(
user=user,
card=card,
defaults={"source": "mathbti"},
)