feat(authentication): add use_nickname to admin

This commit is contained in:
Shreyas Mayya 2022-01-30 13:27:13 -05:00
parent a09d97fb8e
commit cef0799efd
No known key found for this signature in database
GPG Key ID: 42522E3641BA2E31
3 changed files with 13 additions and 1 deletions

View File

@ -20,6 +20,7 @@ class UserAdmin(admin.ModelAdmin):
"email", "email",
"password", "password",
"accepted_terms", "accepted_terms",
"use_nickname",
"is_staff", "is_staff",
"is_superuser", "is_superuser",
"is_senior", "is_senior",

View File

@ -15,7 +15,7 @@ class User(AbstractUser):
nickname = models.CharField(max_length=30, blank=True) nickname = models.CharField(max_length=30, blank=True)
use_nickname = models.BooleanField( use_nickname = models.BooleanField(
default=(nickname is not None), default=False,
verbose_name="Use nickname instead of first name", 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.", help_text="If this is set, your nickname will be used to identify you across the site.",
) )

View File

@ -130,6 +130,17 @@ class ProfileTest(TJDestsTestCase):
).count(), ).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): def test_testscore_create(self):
"""Tests creating test scores.""" """Tests creating test scores."""