Création des users d'un seul coup
This commit is contained in:
parent
d210fc88c4
commit
2e1051bb2e
1 changed files with 13 additions and 3 deletions
|
@ -322,13 +322,23 @@ def create_users(election, csv_file):
|
|||
"""Crée les votant·e·s pour l'élection donnée, en remplissant les champs
|
||||
`username`, `election` et `full_name`.
|
||||
"""
|
||||
User = get_user_model()
|
||||
|
||||
dialect = csv.Sniffer().sniff(csv_file.readline().decode("utf-8"))
|
||||
csv_file.seek(0)
|
||||
reader = csv.reader(io.StringIO(csv_file.read().decode("utf-8")), dialect)
|
||||
for (username, full_name, email) in reader:
|
||||
election.registered_voters.create(
|
||||
username=f"{election.id}__{username}", email=email, full_name=full_name
|
||||
|
||||
users = [
|
||||
User(
|
||||
election=election,
|
||||
username=f"{election.id}__{username}",
|
||||
email=email,
|
||||
full_name=full_name,
|
||||
)
|
||||
for (username, full_name, email) in reader
|
||||
]
|
||||
|
||||
User.objects.bulk_create(users)
|
||||
|
||||
|
||||
def check_csv(csv_file):
|
||||
|
|
Loading…
Reference in a new issue