Commit 2155dbf5 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

fix middle name handling in Person.

parent bd01e897
...@@ -93,17 +93,12 @@ class Person(Node, LoginAccountProviderMixin, EncryptedPasswordMixin): ...@@ -93,17 +93,12 @@ class Person(Node, LoginAccountProviderMixin, EncryptedPasswordMixin):
def getTitle(self, **kw): def getTitle(self, **kw):
""" """
Returns the title if it exists or a combination of Returns the title if it exists or a combination of
first name and last name first name, middle name and last name
""" """
if self.title == '': if not self.title:
name_list = [] return ' '.join([x for x in (self.getFirstName(),
if self.getFirstName() not in (None, ''): self.getMiddleName(),
name_list.append(self.getFirstName()) self.getLastName()) if x])
if self.getMiddleName() not in (None, ''):
name_list.append(self.getMiddleName())
if self.getLastName() not in (None, ''):
name_list.append(self.getLastName())
return ' '.join(name_list)
else: else:
return self.title return self.title
...@@ -112,17 +107,12 @@ class Person(Node, LoginAccountProviderMixin, EncryptedPasswordMixin): ...@@ -112,17 +107,12 @@ class Person(Node, LoginAccountProviderMixin, EncryptedPasswordMixin):
def getTranslatedTitle(self, **kw): def getTranslatedTitle(self, **kw):
""" """
Returns the title if it exists or a combination of Returns the title if it exists or a combination of
first name and last name first name, middle name and last name
""" """
if self.title == '': if not self.title:
name_list = [] return ' '.join([x for x in (self.getTranslatedFirstName(**kw),
if self.getTranslatedFirstName(**kw) not in (None, ''): self.getTranslatedMiddleName(**kw),
name_list.append(self.getTranslatedFirstName(**kw)) self.getTranslatedLastName(**kw)) if x])
if self.getTranslatedMiddleName(**kw) not in (None, ''):
name_list.append(self.getTranslatedMiddleName(**kw))
if self.getTranslatedLastName(**kw) not in (None, ''):
name_list.append(self.getTranslatedLastName(**kw))
return ' '.join(name_list)
else: else:
return self.title return self.title
...@@ -136,26 +126,6 @@ class Person(Node, LoginAccountProviderMixin, EncryptedPasswordMixin): ...@@ -136,26 +126,6 @@ class Person(Node, LoginAccountProviderMixin, EncryptedPasswordMixin):
def hasTitle(self): def hasTitle(self):
return not not self.getTitle() return not not self.getTitle()
def _setFirstName(self, value):
"""
Update Title if first_name is modified
"""
self._baseSetFirstName(value)
name_list = []
if self.getFirstName(): name_list.append(self.getFirstName())
if self.getLastName(): name_list.append(self.getLastName())
if name_list: self._setTitle(' '.join(name_list))
def _setLastName(self, value):
"""
Update Title if last_name is modified
"""
self._baseSetLastName(value)
name_list = []
if self.getFirstName(): name_list.append(self.getFirstName())
if self.getLastName(): name_list.append(self.getLastName())
if name_list: self._setTitle(' '.join(name_list))
def _setReference(self, value): def _setReference(self, value):
""" """
Set the user id. This method is defined explicitly, because: Set the user id. This method is defined explicitly, because:
......
...@@ -109,6 +109,8 @@ class TestPerson(ERP5TypeTestCase): ...@@ -109,6 +109,8 @@ class TestPerson(ERP5TypeTestCase):
p.setFirstName('first') p.setFirstName('first')
p.setLastName('last') p.setLastName('last')
self.assertEqual('first last', p.getTitle()) self.assertEqual('first last', p.getTitle())
p.setMiddleName('middle')
self.assertEqual('first middle last', p.getTitle())
def testEditFirstNameLastName(self): def testEditFirstNameLastName(self):
# using 'edit' method # using 'edit' method
...@@ -118,13 +120,19 @@ class TestPerson(ERP5TypeTestCase): ...@@ -118,13 +120,19 @@ class TestPerson(ERP5TypeTestCase):
self.assertEqual('first', p.getFirstName()) self.assertEqual('first', p.getFirstName())
self.assertEqual('last', p.getLastName()) self.assertEqual('last', p.getLastName())
self.assertEqual('first last', p.getTitle()) self.assertEqual('first last', p.getTitle())
self.assertEqual('first last', p.getTranslatedTitle())
p.edit(middle_name='middle')
self.assertEqual('first middle last', p.getTitle())
self.assertEqual('first middle last', p.getTranslatedTitle())
def testEditTitleFirstNameLastName(self): def testEditTitleFirstNameLastName(self):
p = self._makeOne(id='person') p = self._makeOne(id='person')
p.edit( first_name='first', p.edit( first_name='first',
last_name='last', last_name='last',
title='title' ) title='title' )
# no infinite loop :) but there's no guarantee on the behaviour self.assertEqual('title', p.getTitle())
p.edit(middle_name='middle')
self.assertEqual('title', p.getTitle())
def testGetTitleOrId(self): def testGetTitleOrId(self):
p = self._makeOne(id='person') p = self._makeOne(id='person')
...@@ -136,6 +144,10 @@ class TestPerson(ERP5TypeTestCase): ...@@ -136,6 +144,10 @@ class TestPerson(ERP5TypeTestCase):
self.assertEqual('first last', p.getTitleOrId()) self.assertEqual('first last', p.getTitleOrId())
self.assertEqual('first last', p.title_or_id()) self.assertEqual('first last', p.title_or_id())
p.edit(middle_name='middle')
self.assertEqual('first middle last', p.getTitleOrId())
self.assertEqual('first middle last', p.title_or_id())
def testHasTitle(self): def testHasTitle(self):
p = self._makeOne(id='person') p = self._makeOne(id='person')
self.assertFalse(p.hasTitle()) self.assertFalse(p.hasTitle())
......
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