From 776b2c7874ef2ed62f7c557f65c1a67bda908bbc Mon Sep 17 00:00:00 2001 From: Virginia Dooley Date: Thu, 20 Jun 2024 12:02:05 +0100 Subject: [PATCH] Check for trailing slash before setting username --- wcivf/apps/people/models.py | 6 +++++- wcivf/apps/people/tests/test_person_models.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/wcivf/apps/people/models.py b/wcivf/apps/people/models.py index 7c3a840b5..f3e974a2d 100644 --- a/wcivf/apps/people/models.py +++ b/wcivf/apps/people/models.py @@ -285,7 +285,11 @@ def instagram_username(self): @property def linkedin_username(self): linkedin_url = self.linkedin_url - return urlparse(linkedin_url).path.split("/")[-2] + # sometimes the url will have a trailing slash and othertimes it won't + # so we need to check for the trailing slash if it exists + if linkedin_url[-1] == "/": + return urlparse(linkedin_url).path.split("/")[-2] + return urlparse(linkedin_url).path.split("/")[-1] @property def youtube_username(self): diff --git a/wcivf/apps/people/tests/test_person_models.py b/wcivf/apps/people/tests/test_person_models.py index 1c5db89de..c537b01d2 100644 --- a/wcivf/apps/people/tests/test_person_models.py +++ b/wcivf/apps/people/tests/test_person_models.py @@ -52,7 +52,7 @@ def test_instagram_username(self): assert self.person.instagram_username == "vickyfordmp" def test_linkedin_username(self): - self.person.linkedin_url = "https://www.linkedin.com/in/vicky-ford/" + self.person.linkedin_url = "https://www.linkedin.com/in/vicky-ford" assert self.person.linkedin_username == "vicky-ford" def test_youtube_username(self):