diff --git a/cadasta/accounts/models.py b/cadasta/accounts/models.py index 0f3e5f392..5269d6822 100644 --- a/cadasta/accounts/models.py +++ b/cadasta/accounts/models.py @@ -67,6 +67,17 @@ def get_full_name(self): """ return self.full_name + def get_display_name(self): + """ + Returns the display name. + If full name is present then return full name as display name + else return username. + """ + if self.full_name != '': + return self.full_name + else: + return self.username + @receiver(models.signals.post_save, sender=User) def assign_default_policy(sender, instance, **kwargs): diff --git a/cadasta/accounts/tests/test_forms.py b/cadasta/accounts/tests/test_forms.py index 9d85bc47c..50565ed2e 100644 --- a/cadasta/accounts/tests/test_forms.py +++ b/cadasta/accounts/tests/test_forms.py @@ -89,6 +89,21 @@ def test_update_user(self): user.refresh_from_db() assert user.full_name == 'John Lennon' + assert user.get_display_name == 'John Lennon' + + def test_update_user_with_empty_full_name(self): + user = UserFactory.create(username='imagine71', + email='john@beatles.uk') + data = { + 'username': 'imagine71', + 'email': 'john@beatles.uk', + 'full_name': '', + } + form = ProfileForm(data, instance=user) + form.save() + + user.refresh_from_db() + assert user.get_display_name() == 'imagine71' def test_update_user_with_existing_username(self): UserFactory.create(username='existing') diff --git a/cadasta/templates/organization/organization_members.html b/cadasta/templates/organization/organization_members.html index a25b840de..e7e6364a2 100644 --- a/cadasta/templates/organization/organization_members.html +++ b/cadasta/templates/organization/organization_members.html @@ -34,7 +34,7 @@