From 2ef9f49a110ec2e43efef768cc252f7d1f62f90e Mon Sep 17 00:00:00 2001 From: Jameson Liu Date: Thu, 14 Mar 2024 15:04:31 -0700 Subject: [PATCH 1/2] point of contact --- hknweb/events/forms/event/create.py | 1 + ...icalview_options_event_point_of_contact.py | 21 +++++++++++++++++++ hknweb/events/models/event.py | 1 + .../views/event_transactions/show_event.py | 1 + hknweb/templates/events/show_details.html | 1 + poetry.lock | 4 ++-- 6 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 hknweb/events/migrations/0013_alter_icalview_options_event_point_of_contact.py diff --git a/hknweb/events/forms/event/create.py b/hknweb/events/forms/event/create.py index 7688ee35..e8fa9760 100644 --- a/hknweb/events/forms/event/create.py +++ b/hknweb/events/forms/event/create.py @@ -30,6 +30,7 @@ class Meta: model = Event fields = ( "name", + "point_of_contact", "location", "description", "event_type", diff --git a/hknweb/events/migrations/0013_alter_icalview_options_event_point_of_contact.py b/hknweb/events/migrations/0013_alter_icalview_options_event_point_of_contact.py new file mode 100644 index 00000000..c13f7938 --- /dev/null +++ b/hknweb/events/migrations/0013_alter_icalview_options_event_point_of_contact.py @@ -0,0 +1,21 @@ +# Generated by Django 4.2.5 on 2024-03-14 22:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("events", "0012_icalview"), + ] + + operations = [ + migrations.AlterModelOptions( + name="icalview", + options={"verbose_name": "iCal view"}, + ), + migrations.AddField( + model_name="event", + name="point_of_contact", + field=models.CharField(default="N/A", max_length=255), + ), + ] diff --git a/hknweb/events/models/event.py b/hknweb/events/models/event.py index 41e893e0..fe8d7fb2 100644 --- a/hknweb/events/models/event.py +++ b/hknweb/events/models/event.py @@ -13,6 +13,7 @@ class Event(models.Model): name = models.CharField(max_length=255) + point_of_contact = models.CharField(max_length=255, default="N/A") start_time = models.DateTimeField() end_time = models.DateTimeField() location = models.CharField(max_length=255) diff --git a/hknweb/events/views/event_transactions/show_event.py b/hknweb/events/views/event_transactions/show_event.py index e26f329c..a0079e3f 100644 --- a/hknweb/events/views/event_transactions/show_event.py +++ b/hknweb/events/views/event_transactions/show_event.py @@ -30,6 +30,7 @@ def show_details_helper(request, id, back_link: str, can_edit: bool): context = { "event": event, + "event_point_of_contact": markdownify(event.point_of_contact), "event_description": markdownify(event.description), "event_location": format_url(event.location), "user_access_level": ACCESSLEVEL_TO_DESCRIPTION[get_access_level(request.user)], diff --git a/hknweb/templates/events/show_details.html b/hknweb/templates/events/show_details.html index a627ba46..3ca061a8 100644 --- a/hknweb/templates/events/show_details.html +++ b/hknweb/templates/events/show_details.html @@ -114,6 +114,7 @@

{{ event.name }}

{{ event_description | safe }}

+

Point of Contact: {{ event.point_of_contact}}

Event Type: {{ event.event_type }}

Location: {{ event_location }}

Date(s) and Time(s): {{ event | process_event_time }}

diff --git a/poetry.lock b/poetry.lock index 39550192..21fbf236 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. [[package]] name = "asgiref" @@ -1298,4 +1298,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "~3.9" -content-hash = "3a827c3e82f8a1c5ae08b374c4f246ce5517e55a6675324326cb309fb781785c" \ No newline at end of file +content-hash = "1c0a4ce9a7ac1803bf53e04d261ffa3dc9193777e0f0aef47dc6677364784502" From 822cd78ad049ef8928abe0a8263644f466e709d2 Mon Sep 17 00:00:00 2001 From: Jameson Liu Date: Wed, 10 Apr 2024 22:27:07 -0700 Subject: [PATCH 2/2] case insensitive username and duplicate email check during provisioning --- hknweb/forms.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/hknweb/forms.py b/hknweb/forms.py index 49a52580..ee2287d4 100644 --- a/hknweb/forms.py +++ b/hknweb/forms.py @@ -172,7 +172,7 @@ def add_messages(self, request) -> None: if invalid_emails: messages.error( request, - f"All accounts created successfully except the following with invalid emails: {invalid_emails}. As a reminder, all emails must end in '@berkeley.edu'.", + f"All accounts created successfully except the following with invalid or existing emails: {invalid_emails}. As a reminder, all emails must end in '@berkeley.edu'.", ) else: messages.info(request, "All accounts successfully created!") @@ -206,6 +206,7 @@ def email_to_username(email: str) -> str: # Get existing usernames usernames = [] + emails = [] invalid_emails = [] for row in rows: email = row["Berkeley email"] @@ -213,15 +214,22 @@ def email_to_username(email: str) -> str: if username: usernames.append(username) + emails.append(email) else: invalid_emails.append(email) row["username"] = username - existing_usernames = set( + existing_usernames = {u.lower() for u in User.objects.filter(username__in=usernames).values_list( "username", flat=True ) + } + + existing_emails = set( + User.objects.filter(email__in=emails).values_list( + "email", flat=True + ) ) # Setup account provisioning utils @@ -238,8 +246,9 @@ def generate_password() -> str: email_information = [] 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 username is None or already exists or email already exists, skip provisioning + if (row["username"] is None) or (row["username"].lower() in existing_usernames) or (row["Berkeley email"] in existing_emails): + invalid_emails.append(row["Berkeley email"]) continue # Generate a password