From 95ee5c52aa04180f44c643b42181ed871cb2826f Mon Sep 17 00:00:00 2001 From: Patrick Bales Date: Mon, 27 Nov 2023 00:49:26 -0500 Subject: [PATCH 1/9] Prelim implementation; added bulk account creation --- hknweb/forms.py | 53 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/hknweb/forms.py b/hknweb/forms.py index 49a52580..8497679f 100644 --- a/hknweb/forms.py +++ b/hknweb/forms.py @@ -236,30 +236,51 @@ 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, - ) + password=generate_password(), + )) + + 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: user.save() - - # Add user to the candidates group group.user_set.add(user) - - # Add information for sending emails - email_information.append((user, password)) + email_information.append((user, user.password)) + + # for row in rows: + # # If username is None or already exists, skip provisioning + # 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( + # 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 + # group.user_set.add(user) + + # # Add information for sending emails + # email_information.append((user, password)) self.email_information = email_information From b6d7b66a32e0df9408e9075b81a7b41d3b69402e Mon Sep 17 00:00:00 2001 From: Patrick Bales Date: Mon, 27 Nov 2023 01:22:08 -0500 Subject: [PATCH 2/9] Deleted old implementation --- hknweb/forms.py | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/hknweb/forms.py b/hknweb/forms.py index 8497679f..cef2d187 100644 --- a/hknweb/forms.py +++ b/hknweb/forms.py @@ -258,30 +258,6 @@ def generate_password() -> str: group.user_set.add(user) email_information.append((user, user.password)) - # for row in rows: - # # If username is None or already exists, skip provisioning - # 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( - # 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 - # group.user_set.add(user) - - # # Add information for sending emails - # email_information.append((user, password)) - self.email_information = email_information # Save information for adding messages From f9465e36739509e18b62d39754678a33f879c986 Mon Sep 17 00:00:00 2001 From: Patrick Bales Date: Wed, 29 Nov 2023 02:11:56 -0500 Subject: [PATCH 3/9] Fixed saving error --- hknweb/forms.py | 1 - 1 file changed, 1 deletion(-) diff --git a/hknweb/forms.py b/hknweb/forms.py index cef2d187..91c90d9f 100644 --- a/hknweb/forms.py +++ b/hknweb/forms.py @@ -254,7 +254,6 @@ def generate_password() -> str: # Save each user, add to candidate group set, and add information for emails email_information = [] for user in users: - user.save() group.user_set.add(user) email_information.append((user, user.password)) From fb2f0755e026fdba0f5c15d1ae36029233925613 Mon Sep 17 00:00:00 2001 From: Patrick Bales Date: Wed, 29 Nov 2023 02:12:39 -0500 Subject: [PATCH 4/9] Poetry and migration error fix --- .../migrations/0013_alter_icalview_options.py | 16 ++++++++++++++++ poetry.lock | 4 ---- pyproject.toml | 3 --- 3 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 hknweb/events/migrations/0013_alter_icalview_options.py diff --git a/hknweb/events/migrations/0013_alter_icalview_options.py b/hknweb/events/migrations/0013_alter_icalview_options.py new file mode 100644 index 00000000..37ec063c --- /dev/null +++ b/hknweb/events/migrations/0013_alter_icalview_options.py @@ -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"}, + ), + ] diff --git a/poetry.lock b/poetry.lock index 2e8c6f32..6973469b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1298,8 +1298,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "~3.9" -<<<<<<< HEAD content-hash = "3a827c3e82f8a1c5ae08b374c4f246ce5517e55a6675324326cb309fb781785c" -======= -content-hash = "72c98c5ebe3db16f613c40c9ef8e80ac30f7e48aeb69ff86d63fb7583adb9dc3" ->>>>>>> aeb8ef26d262cbd2094143129e97b43fb58f6bfd diff --git a/pyproject.toml b/pyproject.toml index 3249d56c..3d0d4695 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,11 +15,8 @@ fabric = "^3.2.2" django-autocomplete-light = "^3.9.7" djangorestframework = "^3.14.0" google-api-python-client = "^2.99.0" -<<<<<<< HEAD pillow = "^9.5.0" -======= icalendar = "^5.0.10" ->>>>>>> aeb8ef26d262cbd2094143129e97b43fb58f6bfd [tool.poetry.group.prod] optional = true From 3abe66c1b4d029933076e2c4c1ef9524af5ea274 Mon Sep 17 00:00:00 2001 From: Patrick Bales Date: Wed, 29 Nov 2023 02:58:11 -0500 Subject: [PATCH 5/9] Implemented recommended changes --- .../migrations/0013_alter_icalview_options.py | 16 ---------------- hknweb/forms.py | 10 +++++++--- 2 files changed, 7 insertions(+), 19 deletions(-) delete mode 100644 hknweb/events/migrations/0013_alter_icalview_options.py diff --git a/hknweb/events/migrations/0013_alter_icalview_options.py b/hknweb/events/migrations/0013_alter_icalview_options.py deleted file mode 100644 index 37ec063c..00000000 --- a/hknweb/events/migrations/0013_alter_icalview_options.py +++ /dev/null @@ -1,16 +0,0 @@ -# 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"}, - ), - ] diff --git a/hknweb/forms.py b/hknweb/forms.py index 91c90d9f..7aa195ec 100644 --- a/hknweb/forms.py +++ b/hknweb/forms.py @@ -241,13 +241,17 @@ def generate_password() -> str: for row in rows: if row["username"] is None or row["username"] in existing_usernames: continue - user_data.append(User( + + user = User( username=row["username"], first_name=row["First name"], last_name=row["Last name"], email=row["Berkeley email"], - password=generate_password(), - )) + ) + + password = generate_password() + user.set_password(password) + user_data.append(user) users = User.objects.bulk_create(user_data) # Bulk process accounts into database From 205740e06003819792f6091436077470bd108a26 Mon Sep 17 00:00:00 2001 From: Patrick Bales Date: Wed, 29 Nov 2023 03:24:12 -0500 Subject: [PATCH 6/9] Add non-hashed pwrd to email; add users to user_set in bulk --- hknweb/forms.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/hknweb/forms.py b/hknweb/forms.py index 7aa195ec..c1fc7d3a 100644 --- a/hknweb/forms.py +++ b/hknweb/forms.py @@ -238,6 +238,7 @@ def generate_password() -> str: # Process user data into useable structs user_data = [] + user_pwrds = [] for row in rows: if row["username"] is None or row["username"] in existing_usernames: continue @@ -250,16 +251,20 @@ def generate_password() -> str: ) password = generate_password() + + user_pwrds.append(password) user.set_password(password) user_data.append(user) users = User.objects.bulk_create(user_data) # Bulk process accounts into database + group.user_set.add(*users) # Save each user, add to candidate group set, and add information for emails email_information = [] - for user in users: - group.user_set.add(user) - email_information.append((user, user.password)) + for i in range(len(users)): + user = users[i] + pwrd = user_pwrds[i] + email_information.append((user, pwrd)) self.email_information = email_information From a2165fb876c87562f19c6f3bf6a55162acffeadc Mon Sep 17 00:00:00 2001 From: Patrick Bales Date: Wed, 29 Nov 2023 03:25:48 -0500 Subject: [PATCH 7/9] Var change --- hknweb/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hknweb/forms.py b/hknweb/forms.py index c1fc7d3a..eac8e5d6 100644 --- a/hknweb/forms.py +++ b/hknweb/forms.py @@ -261,7 +261,7 @@ def generate_password() -> str: # Save each user, add to candidate group set, and add information for emails email_information = [] - for i in range(len(users)): + for i in range(len(user_data)): user = users[i] pwrd = user_pwrds[i] email_information.append((user, pwrd)) From eace308332745769b36d23d67e1c9a9f221f251e Mon Sep 17 00:00:00 2001 From: Patrick Bales Date: Wed, 29 Nov 2023 03:26:35 -0500 Subject: [PATCH 8/9] Var change --- hknweb/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hknweb/forms.py b/hknweb/forms.py index eac8e5d6..c1fc7d3a 100644 --- a/hknweb/forms.py +++ b/hknweb/forms.py @@ -261,7 +261,7 @@ def generate_password() -> str: # Save each user, add to candidate group set, and add information for emails email_information = [] - for i in range(len(user_data)): + for i in range(len(users)): user = users[i] pwrd = user_pwrds[i] email_information.append((user, pwrd)) From d7af16ebeea1ecd9cc5ab6ff20341e03de25e436 Mon Sep 17 00:00:00 2001 From: Patrick Bales Date: Wed, 29 Nov 2023 14:27:35 -0500 Subject: [PATCH 9/9] Created profiles for users --- hknweb/forms.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hknweb/forms.py b/hknweb/forms.py index c1fc7d3a..c19fb0fd 100644 --- a/hknweb/forms.py +++ b/hknweb/forms.py @@ -237,8 +237,8 @@ def generate_password() -> str: return password # Process user data into useable structs - user_data = [] - user_pwrds = [] + user_data, user_pwrds = [], [] + profile_data = [] for row in rows: if row["username"] is None or row["username"] in existing_usernames: continue @@ -255,8 +255,12 @@ def generate_password() -> str: user_pwrds.append(password) user.set_password(password) user_data.append(user) + + profile = Profile(user=user) + profile_data.append(profile) users = User.objects.bulk_create(user_data) # Bulk process accounts into database + Profile.objects.bulk_create(profile_data) group.user_set.add(*users) # Save each user, add to candidate group set, and add information for emails