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.
This commit is contained in:
parent
85b1e974ff
commit
63fff6ca7c
4 changed files with 159 additions and 15 deletions
32
kfet/migrations/0067_deleted_account.py
Normal file
32
kfet/migrations/0067_deleted_account.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
# 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)]
|
Loading…
Add table
Add a link
Reference in a new issue