From 24a78543eb37e3c3247a75a9acdd58f497f73ea9 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Fri, 30 Aug 2024 17:35:32 +0200 Subject: [PATCH] Remove discriminator from bot logs view When a user does not have a discriminator, do not display it anymore. Behaviour for users with discriminators (for historic infractions is unchanged). --- pydis_site/apps/api/models/bot/user.py | 4 +++- pydis_site/apps/api/tests/test_models.py | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pydis_site/apps/api/models/bot/user.py b/pydis_site/apps/api/models/bot/user.py index 4d317b8e1..15e83b2f6 100644 --- a/pydis_site/apps/api/models/bot/user.py +++ b/pydis_site/apps/api/models/bot/user.py @@ -76,7 +76,9 @@ class User(ModelReprMixin, models.Model): def __str__(self): """Returns the name and discriminator for the current user, for display purposes.""" - return f"{self.name}#{self.discriminator:04d}" + if self.discriminator: + return f"{self.name}#{self.discriminator:04d}" + return self.name @property def top_role(self) -> Role: diff --git a/pydis_site/apps/api/tests/test_models.py b/pydis_site/apps/api/tests/test_models.py index 456ac4085..0804384cf 100644 --- a/pydis_site/apps/api/tests/test_models.py +++ b/pydis_site/apps/api/tests/test_models.py @@ -187,3 +187,9 @@ def test_nomination_str_representation(self): "Nomination of Hemlock's Cat#7777 (active)", str(self.nomination) ) + + +class UserTests(SimpleTestCase): + def test_str_without_discriminator(self) -> None: + user = User(name="lemonfannumber1") + self.assertEqual(str(user), "lemonfannumber1")