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

[#1701] Changed User.get_full_name() to prefer .display_name over .first_name #769

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/open_inwoner/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ def seed(self):
return self._seed

def get_full_name(self):
parts = (self.first_name, self.infix, self.last_name)
# validator allowed spaces as values
first_name = self.display_name.strip() or self.first_name.strip()
parts = (first_name, self.infix.strip(), self.last_name.strip())
return " ".join(p for p in parts if p)

def get_short_name(self):
Expand Down
17 changes: 17 additions & 0 deletions src/open_inwoner/accounts/tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ def test_get_full_name(self):
user = User(first_name="", infix="", last_name="Bar")
self.assertEqual(user.get_full_name(), "Bar")

# use display_name instead of first_name
user = User(first_name="Foo", display_name="Flexi", infix="de", last_name="Bar")
self.assertEqual(user.get_full_name(), "Flexi de Bar")

# spaces everywhere
user = User(first_name="Foo", display_name=" ", infix="de", last_name="Bar")
self.assertEqual(user.get_full_name(), "Foo de Bar")

user = User(
first_name=" ",
display_name=" ",
infix=" ",
last_name=" ",
email="[email protected]",
)
self.assertEqual(user.get_full_name(), "")

@freeze_time("2021-07-07 12:00:00")
def test_get_age_same_day(self):
with freeze_time("1990-07-07"):
Expand Down
Loading