Fixe un bug avec authens en créant le CASAccount associé à l'user
This commit is contained in:
parent
2cd6e228fb
commit
047ef80bec
1 changed files with 13 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
|||
from datetime import date
|
||||
|
||||
from authens.models import CASAccount
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
|
@ -36,7 +38,7 @@ class Command(BaseCommand):
|
|||
else:
|
||||
promo = self.get_current_promo()
|
||||
|
||||
if promo < 2000 or promo > 2100:
|
||||
if promo is not None and (promo < 2000 or promo > 2100):
|
||||
raise CommandError("Promotion invalide : {}".format(promo))
|
||||
|
||||
verbosity = options["verbosity"]
|
||||
|
@ -48,7 +50,7 @@ class Command(BaseCommand):
|
|||
)
|
||||
|
||||
# On vire les élèves déjà existants
|
||||
existing_users = set(User.objects.values_list("username", flat=True))
|
||||
existing_users = set(CASAccount.objects.values_list("cas_login", flat=True))
|
||||
clippers = [
|
||||
clipper for clipper in clipper_list if clipper.uid not in existing_users
|
||||
]
|
||||
|
@ -62,9 +64,14 @@ class Command(BaseCommand):
|
|||
users_to_create = []
|
||||
profiles_to_create = []
|
||||
dept_m2m_to_create = []
|
||||
cas_account_to_create = []
|
||||
|
||||
for clipper in clippers:
|
||||
user = User(username=clipper.uid, email=clipper.email)
|
||||
cas_account = CASAccount(
|
||||
user=user, cas_login=clipper.uid, entrance_year=clipper.year
|
||||
)
|
||||
cas_account_to_create.append(cas_account)
|
||||
profile = Profile(user=user, full_name=clipper.name, promotion=clipper.year)
|
||||
users_to_create.append(user)
|
||||
profiles_to_create.append(profile)
|
||||
|
@ -83,10 +90,14 @@ class Command(BaseCommand):
|
|||
# p.id = pid
|
||||
|
||||
# _manual_ids(User, users_to_create)
|
||||
# _manual_ids(CASAccount, cas_account_to_create)
|
||||
# _manual_ids(Profile, profiles_to_create)
|
||||
# _manual_ids(Profile.department.through, dept_m2m_to_create)
|
||||
|
||||
User.objects.bulk_create(users_to_create)
|
||||
for cas_account in cas_account_to_create:
|
||||
cas_account.user_id = cas_account.user.id
|
||||
CASAccount.objects.bulk_create(cas_account_to_create)
|
||||
for profile in profiles_to_create:
|
||||
profile.user_id = profile.user.id
|
||||
Profile.objects.bulk_create(profiles_to_create)
|
||||
|
|
Loading…
Add table
Reference in a new issue