Commit 48bc52d3 authored by Jérome Perrin's avatar Jérome Perrin

ERP5: make Person.getTitle fallback consistent with Base

when no title, fallback to reference then id
parent e41c43b8
......@@ -96,11 +96,12 @@ class Person(Node, LoginAccountProviderMixin, EncryptedPasswordMixin):
first name, middle name and last name
"""
if not self.title:
return ' '.join([x for x in (self.getFirstName(),
title = ' '.join([x for x in (self.getFirstName(),
self.getMiddleName(),
self.getLastName()) if x])
else:
return self.title
if title:
return title
return super(Person, self).getTitle(**kw)
security.declareProtected(Permissions.AccessContentsInformation,
'getTranslatedTitle')
......@@ -110,11 +111,12 @@ class Person(Node, LoginAccountProviderMixin, EncryptedPasswordMixin):
first name, middle name and last name
"""
if not self.title:
return ' '.join([x for x in (self.getTranslatedFirstName(**kw),
title = ' '.join([x for x in (self.getTranslatedFirstName(**kw),
self.getTranslatedMiddleName(**kw),
self.getTranslatedLastName(**kw)) if x])
else:
return self.title
if title:
return title
return super(Person, self).getTranslatedTitle(**kw)
security.declareProtected(Permissions.AccessContentsInformation,
'title_or_id')
......@@ -124,7 +126,10 @@ class Person(Node, LoginAccountProviderMixin, EncryptedPasswordMixin):
security.declareProtected(Permissions.AccessContentsInformation,
'hasTitle')
def hasTitle(self):
return not not self.getTitle()
return self.hasFirstName() or \
self.hasLastName() or \
self.hasMiddleName() or \
self._baseHasTitle()
def _setReference(self, value):
"""
......
......@@ -90,9 +90,37 @@ class TestPerson(ERP5TypeTestCase):
self.assertEqual(person_copy_obj.getReference(), person.getReference())
# title & first_name, last_name
def testEmptyTitle(self):
p = self._makeOne()
self.assertEqual('', p.getTitle())
def testEmptyTitleFallbackOnId(self):
p = self._makeOne(id=self.id())
self.assertEqual(self.id(), p.getTitle())
def testEmptyTranslatedTitleFallbackOnId(self):
p = self._makeOne(id=self.id())
self.assertEqual(self.id(), p.getTranslatedTitle())
def testEmptyCompactTitleFallbackOnId(self):
p = self._makeOne(id=self.id())
self.assertEqual(self.id(), p.getCompactTitle())
def testEmptyCompactTranslatedTitleFallbackOnId(self):
p = self._makeOne(id=self.id())
self.assertEqual(self.id(), p.getCompactTranslatedTitle())
def testEmptyTitleFallbackOnReference(self):
p = self._makeOne(reference='reference')
self.assertEqual('reference', p.getTitle())
def testEmptyTranslatedTitleFallbackOnReference(self):
p = self._makeOne(reference='reference')
self.assertEqual('reference', p.getTranslatedTitle())
def testEmptyCompactTitleFallbackOnReference(self):
p = self._makeOne(reference='reference')
self.assertEqual('reference', p.getCompactTitle())
def testEmptyCompactTranslatedTitleFallbackOnReference(self):
p = self._makeOne(reference='reference')
self.assertEqual('reference', p.getCompactTranslatedTitle())
def testSetFirstName(self):
p = self._makeOne()
......@@ -112,6 +140,22 @@ class TestPerson(ERP5TypeTestCase):
p.setMiddleName('middle')
self.assertEqual('first middle last', p.getTitle())
def testTranslatedTitleFromFirstLastName(self):
p = self._makeOne(id='person')
p.setFirstName('first')
p.setLastName('last')
self.assertEqual('first last', p.getTranslatedTitle())
p.setMiddleName('middle')
self.assertEqual('first middle last', p.getTranslatedTitle())
def testCompactTranslatedTitleFromFirstLastName(self):
p = self._makeOne(id='person')
p.setFirstName('first')
p.setLastName('last')
self.assertEqual('first last', p.getCompactTranslatedTitle())
p.setMiddleName('middle')
self.assertEqual('first middle last', p.getCompactTranslatedTitle())
def testEditFirstNameLastName(self):
# using 'edit' method
p = self._makeOne(id='person')
......
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