Skip to content

Commit

Permalink
Fix for show username in member permissions page
Browse files Browse the repository at this point in the history
The issue #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
  • Loading branch information
kavindya89 committed Sep 14, 2016
1 parent e1b1155 commit b27043a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
11 changes: 11 additions & 0 deletions cadasta/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
15 changes: 15 additions & 0 deletions cadasta/accounts/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='[email protected]')
data = {
'username': 'imagine71',
'email': '[email protected]',
'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')
Expand Down
2 changes: 1 addition & 1 deletion cadasta/templates/organization/organization_members.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h2>{% trans "Members" %}</h2>
<tbody>
{% for user in organization.users.all %}
<tr class="linked" onclick="window.document.location='{% url 'organization:members_edit' slug=organization.slug username=user.username %}';">
<td>{{ user.get_full_name }}
<td>{{ user.get_display_name }}
<div class="hidden-sm hidden-md hidden-lg">
{{ user.username }}<br />
{{ user.email }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="row">
<!-- Main text -->
<div class="col-md-12 main-text">
<h2>{% trans "Member" %}: <span class="text-capitalize">{{ object.get_full_name }}</span></h2>
<h2>{% trans "Member" %}: <span class="text-capitalize">{{ object.get_display_name }}</span></h2>
<form method="POST" action="" class="org-member-edit" novalidate>
{% csrf_token %}
<div class="row">
Expand Down

0 comments on commit b27043a

Please sign in to comment.