From cef0799efde6cc6a39f5866fa7b875b45ffb3170 Mon Sep 17 00:00:00 2001 From: Shreyas Mayya <2022smayya@tjhsst.edu> Date: Sun, 30 Jan 2022 13:27:13 -0500 Subject: [PATCH] feat(authentication): add use_nickname to admin --- tjdests/apps/authentication/admin.py | 1 + tjdests/apps/authentication/models.py | 2 +- tjdests/apps/profile/tests.py | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tjdests/apps/authentication/admin.py b/tjdests/apps/authentication/admin.py index a6d50e3..c5050e4 100644 --- a/tjdests/apps/authentication/admin.py +++ b/tjdests/apps/authentication/admin.py @@ -20,6 +20,7 @@ class UserAdmin(admin.ModelAdmin): "email", "password", "accepted_terms", + "use_nickname", "is_staff", "is_superuser", "is_senior", diff --git a/tjdests/apps/authentication/models.py b/tjdests/apps/authentication/models.py index 02ec2a3..7d98f64 100644 --- a/tjdests/apps/authentication/models.py +++ b/tjdests/apps/authentication/models.py @@ -15,7 +15,7 @@ class User(AbstractUser): nickname = models.CharField(max_length=30, blank=True) use_nickname = models.BooleanField( - default=(nickname is not None), + default=False, verbose_name="Use nickname instead of first name", help_text="If this is set, your nickname will be used to identify you across the site.", ) diff --git a/tjdests/apps/profile/tests.py b/tjdests/apps/profile/tests.py index fcea528..9c787bb 100644 --- a/tjdests/apps/profile/tests.py +++ b/tjdests/apps/profile/tests.py @@ -130,6 +130,17 @@ class ProfileTest(TJDestsTestCase): ).count(), ) + # Test nickname/preferred name feature + user = self.login(accept_tos=True, make_student=True) + user.first_name = "Dank" + user.nickname = "Memer" + # Should use nickname ("Memer") if option set + user.use_nickname = True + self.assertEqual("Memer", user.preferred_name) + # Should use first name ("Dank") if option not set + user.use_nickname = False + self.assertEqual("Dank", user.preferred_name) + def test_testscore_create(self): """Tests creating test scores."""