Skip to content

Commit

Permalink
Fix getting chul name. Just return firstname if lastname is null.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarika committed Feb 24, 2016
1 parent c655db3 commit 477ffec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion chul/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ def __str__(self):

@property
def name(self):
return "{} {}".format(self.first_name, self.last_name).strip()
if self.first_name and self.last_name:
return "{} {}".format(self.first_name, self.last_name).strip()
else:
return self.first_name


@reversion.register
Expand Down
9 changes: 9 additions & 0 deletions chul/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ def test_save(self):
mommy.make(CommunityHealthWorker)
self.assertEquals(1, CommunityHealthWorker.objects.count())

def test_name(self):
worker = mommy.make(CommunityHealthWorker,
first_name='Test', last_name='Test')
self.assertEquals('Test Test', worker.name)

worker = mommy.make(CommunityHealthWorker,
first_name='Test', last_name=None)
self.assertEquals('Test', worker.name)


class TestCommunityHealthWorkerContact(TestCase):

Expand Down

0 comments on commit 477ffec

Please sign in to comment.