Always quote nicknames.

Otherwise it's possible to set your nickname to 'John Doe' and from the front end you can't tell that it's a nickname
parent 225b061f
...@@ -414,7 +414,7 @@ class Profile(models.Model): ...@@ -414,7 +414,7 @@ class Profile(models.Model):
def display_name(self): def display_name(self):
pref = self.display_name_preference pref = self.display_name_preference
if pref == 'nickname' and self.nickname is not None: if pref == 'nickname' and self.nickname is not None:
return self.nickname return f"'{self.nickname}'"
elif pref == 'firstname': elif pref == 'firstname':
return self.user.first_name return self.user.first_name
elif pref == 'initials': elif pref == 'initials':
...@@ -436,7 +436,7 @@ class Profile(models.Model): ...@@ -436,7 +436,7 @@ class Profile(models.Model):
pref = self.display_name_preference pref = self.display_name_preference
if (self.nickname is not None and if (self.nickname is not None and
(pref == 'nickname' or pref == 'nicklast')): (pref == 'nickname' or pref == 'nicklast')):
return self.nickname return f"'{self.nickname}'"
elif pref == 'initials': elif pref == 'initials':
if self.initials: if self.initials:
return '{} {}'.format(self.initials, self.user.last_name) return '{} {}'.format(self.initials, self.user.last_name)
......
...@@ -113,8 +113,8 @@ class MemberDisplayNameTest(TestCase): ...@@ -113,8 +113,8 @@ class MemberDisplayNameTest(TestCase):
self.assertEqual('Johnny Test', self.profile.display_name()) self.assertEqual('Johnny Test', self.profile.display_name())
self.assertEqual('Johnny', self.profile.short_display_name()) self.assertEqual('Johnny', self.profile.short_display_name())
self.profile.nickname = 'John' self.profile.nickname = 'John'
self.assertEqual('John', self.profile.display_name()) self.assertEqual("'John'", self.profile.display_name())
self.assertEqual('John', self.profile.short_display_name()) self.assertEqual("'John'", self.profile.short_display_name())
def test_check_display_name_firstname(self): def test_check_display_name_firstname(self):
self.profile.display_name_preference = 'firstname' self.profile.display_name_preference = 'firstname'
...@@ -143,4 +143,4 @@ class MemberDisplayNameTest(TestCase): ...@@ -143,4 +143,4 @@ class MemberDisplayNameTest(TestCase):
self.assertEqual('Johnny', self.profile.short_display_name()) self.assertEqual('Johnny', self.profile.short_display_name())
self.profile.nickname = 'John' self.profile.nickname = 'John'
self.assertEqual('\'John\' Test', self.profile.display_name()) self.assertEqual('\'John\' Test', self.profile.display_name())
self.assertEqual('John', self.profile.short_display_name()) self.assertEqual('\'John\'', self.profile.short_display_name())
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment