Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Candidate Account Provision to Use Bulk Creation #567

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
16 changes: 16 additions & 0 deletions hknweb/events/migrations/0013_alter_icalview_options.py
PBales1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 4.2.5 on 2023-11-29 07:09

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("events", "0012_icalview"),
]

operations = [
migrations.AlterModelOptions(
name="icalview",
options={"verbose_name": "iCal view"},
),
]
30 changes: 13 additions & 17 deletions hknweb/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,30 +236,26 @@ def generate_password() -> str:

return password

email_information = []
# Process user data into useable structs
user_data = []
for row in rows:
# If username is None or already exists, skip provisioning
if (row["username"] is None) or (row["username"] in existing_usernames):
if row["username"] is None or row["username"] in existing_usernames:
continue

# Generate a password
password = generate_password()

# Construct user object
user = User.objects.create_user(
user_data.append(User(
username=row["username"],
first_name=row["First name"],
last_name=row["Last name"],
email=row["Berkeley email"],
password=password,
)
user.save()

# Add user to the candidates group
password=generate_password(),
oliver-ni marked this conversation as resolved.
Show resolved Hide resolved
))

users = User.objects.bulk_create(user_data) # Bulk process accounts into database

# Save each user, add to candidate group set, and add information for emails
email_information = []
for user in users:
group.user_set.add(user)
PBales1 marked this conversation as resolved.
Show resolved Hide resolved

# Add information for sending emails
email_information.append((user, password))
email_information.append((user, user.password))
PBales1 marked this conversation as resolved.
Show resolved Hide resolved

self.email_information = email_information

Expand Down