kpsul/kfet/migrations/0067_deleted_account.py
Ludovic Stephan 63fff6ca7c Setup deleted account
Pour pouvoir supprimer un compte, on crée un compte dummy qui a pour but
de recevoir les objets non supprimables (caisses, transferts/opérations
pour statistiques, etc.). Lors de la délétion d'un compte, tout est
transféré sur le dummy, qui est créé via migration.
2019-05-29 18:29:15 +02:00

32 lines
1 KiB
Python

# Generated by Django 2.2 on 2019-05-23 13:54
from django.db import migrations, models
from kfet import KFET_DELETED_TRIGRAMME, KFET_DELETED_USERNAME
def setup_kfet_deleted_user(apps, schema_editor):
"""
Setup models instances for the kfet deleted account.
Username and trigramme are retrieved from kfet.__init__ module.
Other data are registered here.
"""
User = apps.get_model("auth", "User")
CofProfile = apps.get_model("gestioncof", "CofProfile")
Account = apps.get_model("kfet", "Account")
user, _ = User.objects.update_or_create(
username=KFET_DELETED_USERNAME, defaults={"first_name": "Compte K-Fêt supprimé"}
)
profile, _ = CofProfile.objects.update_or_create(user=user)
account, _ = Account.objects.update_or_create(
cofprofile=profile, defaults={"trigramme": KFET_DELETED_TRIGRAMME}
)
class Migration(migrations.Migration):
dependencies = [("kfet", "0066_on_delete_actions")]
operations = [migrations.RunPython(setup_kfet_deleted_user)]