From b27043af6b6dc76ae915bda2f77d0dc134ac9b49 Mon Sep 17 00:00:00 2001 From: kavindya89 Date: Sun, 11 Sep 2016 00:03:41 +0530 Subject: [PATCH] Fix for show username in member permissions page The issue https://github.com/Cadasta/cadasta-platform/issues/626 suggest that if full name is empty then username should be set in member permission page. This pull request contains fix for it as well as member list page, when full name is empty member column gets blank. So I include to display username if full name is not present --- cadasta/accounts/models.py | 11 +++++++++++ cadasta/accounts/tests/test_forms.py | 15 +++++++++++++++ .../organization/organization_members.html | 2 +- .../organization/organization_members_edit.html | 2 +- 4 files changed, 28 insertions(+), 2 deletions(-) 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 @@

{% trans "Members" %}

{% for user in organization.users.all %} - {{ user.get_full_name }} + {{ user.get_display_name }}