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):
def getTitle(self, **kw):
"""
Returns the title if it exists or a combination of
first name and last name
"""
if self.title == '':
name_list = []
if self.getFirstName() not in (None, ''):
name_list.append(self.getFirstName())
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)
first name, middle name and last name
"""
if not self.title:
return ' '.join([x for x in (self.getFirstName(),
self.getMiddleName(),
self.getLastName()) if x])
else:
return self.title
......@@ -112,17 +107,12 @@ class Person(Node, LoginAccountProviderMixin, EncryptedPasswordMixin):
def getTranslatedTitle(self, **kw):
"""
Returns the title if it exists or a combination of
first name and last name
"""
if self.title == '':
name_list = []
if self.getTranslatedFirstName(**kw) not in (None, ''):
name_list.append(self.getTranslatedFirstName(**kw))
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)
first name, middle name and last name
"""
if not self.title:
return ' '.join([x for x in (self.getTranslatedFirstName(**kw),
self.getTranslatedMiddleName(**kw),
self.getTranslatedLastName(**kw)) if x])
else:
return self.title
......@@ -136,26 +126,6 @@ class Person(Node, LoginAccountProviderMixin, EncryptedPasswordMixin):
def hasTitle(self):
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):
"""
Set the user id. This method is defined explicitly, because:
......
......@@ -109,6 +109,8 @@ class TestPerson(ERP5TypeTestCase):
p.setFirstName('first')
p.setLastName('last')
self.assertEqual('first last', p.getTitle())
p.setMiddleName('middle')
self.assertEqual('first middle last', p.getTitle())
def testEditFirstNameLastName(self):
# using 'edit' method
......@@ -118,13 +120,19 @@ class TestPerson(ERP5TypeTestCase):
self.assertEqual('first', p.getFirstName())
self.assertEqual('last', p.getLastName())
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):
p = self._makeOne(id='person')
p.edit( first_name='first',
last_name='last',
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):
p = self._makeOne(id='person')
......@@ -136,6 +144,10 @@ class TestPerson(ERP5TypeTestCase):
self.assertEqual('first last', p.getTitleOrId())
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):
p = self._makeOne(id='person')
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