From 76fdf073eecee552e772503fa9d674025d4bcb3d Mon Sep 17 00:00:00 2001 From: pinwheeeel Date: Sat, 28 Sep 2024 19:42:52 -0400 Subject: [PATCH 1/2] qol changes to add_clubs --- core/management/commands/add_clubs.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/management/commands/add_clubs.py b/core/management/commands/add_clubs.py index 6c578197..634ce5c3 100644 --- a/core/management/commands/add_clubs.py +++ b/core/management/commands/add_clubs.py @@ -87,6 +87,7 @@ def handle(self, *args, **options): continue self.success(f"New organization: {row[0]}") + row = [token.strip() for token in row] ( organization_name, _, @@ -166,7 +167,7 @@ def handle(self, *args, **options): def get_user_by_email(self, name: str, email: str) -> User | Status: try: - return User.objects.get(email=email) + return User.objects.get(email__iexact=email) except User.DoesNotExist: self.error( f"\t{name}'s email ({email}) not found! Are you sure they registered a metro account with this email?" From ec282f6b65ce8e673e9d43aeb564475a303718a5 Mon Sep 17 00:00:00 2001 From: pinwheeeel Date: Sat, 28 Sep 2024 19:56:12 -0400 Subject: [PATCH 2/2] use regex to make slugs a bit prettier --- core/management/commands/add_clubs.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/management/commands/add_clubs.py b/core/management/commands/add_clubs.py index 634ce5c3..afd34496 100644 --- a/core/management/commands/add_clubs.py +++ b/core/management/commands/add_clubs.py @@ -10,6 +10,7 @@ import csv from io import StringIO +import re import requests from django.core.management.base import BaseCommand @@ -133,10 +134,8 @@ def handle(self, *args, **options): } # this singular comma gave me a run for my money. i have lost my family, my wealth, my sanity, and my soul from the inclusion of this character. # fmt: on - slug="".join( - c.casefold() if c.isalnum() else "-" - for c in organization_name - ).lower() + # remove all non-alphanumeric or whitespace characters (a-z, A-Z, 0-9, space) and then replace spaces with dashes + slug = re.sub(r"[^a-zA-Z0-9\s]", "", organization_name.strip().casefold()).replace(" ", "-") if not Organization.objects.filter(slug=slug).exists(): slug = self.get_corrected_slug_or_not(organization_name, slug)